[英]Django: 'WSGIRequest' object has no attribute 'Post'
Im kinda new to Django and already stuck at some simple POST-problem.我对 Django 有点陌生,并且已经陷入了一些简单的 POST 问题。
Heres the HTML within profile.html:下面是 profile.html 中的 HTML:
<form action="{% url 'profile' %}" method="post">
{% csrf_token %}
<input type="text" placeholder="Weight", name="weight">
<input type="text" placeholder="Reps", name="reps">
<input type="submit">
</form>
And heres the correspoding view:这是对应的观点:
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")
Basically, all I want to do for now, is to print the POST-data dictionary into the Terminal.基本上,我现在要做的就是将 POST 数据字典打印到终端中。 However, I get the following error: AttributeError at /profile/ 'WSGIRequest' object has no attribute 'Post'.
但是,我收到以下错误:/profile/ 'WSGIRequest' 对象的 AttributeError 没有属性 'Post'。 What am I missing?
我错过了什么?
Thanks so much for any help!非常感谢您的帮助!
there is no attribute "Post" on request.请求时没有属性“Post”。 However, there is request.POST
但是,有 request.POST
can you change request.Post
into request.POST
你能把
request.Post
改成request.POST
You have a typo error here你在这里有一个错字错误
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")
request.Post
must be request.POST
all capital request.Post
必须是request.POST
全部大写
Any way if you want to get the value of reps
and weight
based on the form you provided如果您想根据您提供的表格获得
reps
和weight
的值,无论如何
reps = request.POST.get("reps")
weight = request.POST.get("weight")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.