Home > Back-end >  Django: 'WSGIRequest' object has no attribute 'Post'
Django: 'WSGIRequest' object has no attribute 'Post'

Time:11-03

Im kinda new to Django and already stuck at some simple POST-problem.

Heres the HTML within profile.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. However, I get the following error: AttributeError at /profile/ 'WSGIRequest' object has no attribute 'Post'. What am I missing?

Thanks so much for any help!

CodePudding user response:

there is no attribute "Post" on request. However, there is request.POST

can you change request.Post into request.POST

CodePudding user response:

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

Any way if you want to get the value of reps and weight based on the form you provided

reps = request.POST.get("reps")
weight = request.POST.get("weight")
  • Related