You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django提交表单报错'WSGIRequest' object has no attribute 'Post'如何解决

报错原因

你遇到的AttributeError是属性名拼写错误导致的:Django 中WSGIRequest对象存储 POST 请求提交数据的属性名为全大写的POST,你代码中写的request.Post不存在,因此触发异常。

修复方法

将视图函数中打印的代码修改为print(request.POST)即可,修复后的完整视图代码如下:

def profile(request):
    if request.method == "GET":
        return render(request, "userprofile/profile.html")

    elif request.method == "POST":
        print(request.POST)
        return render(request, "userprofile/profile.html")
其他优化建议
  • 你的HTML表单代码中<input type="text" placeholder="Weight", name="weight">一行多了多余的逗号,建议删除避免HTML解析异常,修正后写法为<input type="text" placeholder="Weight" name="weight">
  • 后续如果需要获取表单单个字段的提交值,推荐使用request.POST.get('weight')、request.POST.get('reps')的写法,可避免字段不存在时抛出KeyError

内容的提问来源于stack exchange,提问作者Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 14:45:03