【问题标题】:'WSGIRequest' object has no attribute 'Post' [closed]'WSGIRequest' 对象没有属性'Post' [关闭]
【发布时间】:2015-11-23 10:32:32
【问题描述】:

我是 django 和 python 的新手,我正在尝试从 html 页面中的复选框更新数据库布尔字段。 当我尝试访问 views 方法中的复选框时,会发生此错误:'WSGIRequest' object has no attribute '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() 并给出了同样的错误

【问题讨论】:

    标签: python django django-1.4


    【解决方案1】:

    是错字吗...应该是request.POST

    【讨论】:

      猜你喜欢
      • 2019-01-19
      • 2016-07-30
      • 2017-02-02
      • 2015-04-15
      • 2013-05-20
      • 2016-09-22
      • 2015-10-19
      • 2021-11-16
      • 2012-07-31
      相关资源
      最近更新 更多