简体   繁体   中英

Post parameters missing in django view

I have created a small web app in django, where I am sending a post request with parameters. I can clearly see those parameters present in url in django logs but in views those parameters are missing.

url: [18/Mar/2017 12:04:18] "POST /login/?email=bla@gmail.com&Password=******** HTTP/1.1" 200 20 view.py:

if request.method == 'POST':
    for x in request.POST:
        print(x)
    email = request.POST.get("email","")
    Password = request.POST.get("Password", "")
    print("email: {0}, password:{1}".format(email, Password))

POST parameters are not passed inside the URL, but GET parameters do.

Try this:

if request.method == 'GET':
    for x in request.GET:
        print(x)
    email = request.GET.get("email","")
    password = request.GET.get("Password", "")
    print("email: {0}, password:{1}".format(email, password))

Also, since each visit to a view is a GET one, then there is no reason of doing if request.method == 'GET': . But this is another question.

Your request isnt POST, 'cause the request parameters are being passed in yout GET context. Try to check if your <form method='POST'> its correctly formed to send a post, and your view function accepting just POST methods, by passing:

from django.views.decorators.http import require_http_methods

@require_http_methods(["POST"])
def myview(request):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM