0

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!

2 Answers 2

0

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

can you change request.Post into request.POST

Sign up to request clarification or add additional context in comments.

Comments

0

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")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.