“WSGIRequest”对象没有属性“Post”

2024-03-28 09:54:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我是django和python的新手,我正在尝试从html页面的复选框中更新数据库布尔字段。 当我试图访问views方法中的复选框时,会发生以下错误:“WSGIRequest”对象没有属性“Post”

这是我在HTML中的代码:

<body>

    {% if all_crosses %}

    <form action= 'lines/inventory/' method="POST">
    {%csrf_token%}
    <input type="submit" value="Submit" />

    {% for cross in all_crosses %}
        
        <table style="margin-bottom: 20px">

        <!-- Checkbox + Name -->
        <tr>

            <td>
                {% if cross.exists %}
                <input type="checkbox" value="{{ cross.id }}" name="exist" id="exist{{ forloop.counter }}" checked >
                {% else %}
                <input type="checkbox" value="{{ cross.id }}" name="exist" id="exist{{ forloop.counter }}"  >
                {% endif %}
          </td>
          
          <td>
                <li>Cross Name: {{cross.Name}}</li>
          </td>
       </tr>
      </table>
      {% endfor %}
     </form>
  {% endif %}
  </body>

这是视图中的代码:

def update_existence(request):

   all_crosses = RaisingStatus.objects.all()

   if request.method == "POST":
       if ('exist' in request.POST):
           print('Post')  
           checks = request.Post['exist']
           # My desired processing here

   return render(request, 'lines/inventory.html', {'all_crosses' : all_crosses})

我还尝试了request.Post.getlist()并给出了相同的错误


Tags: nameidinputifvaluerequesthtmltype