request.POST.get() always returning None

I am completely new to django , you can I just started it today

when I am making a POST request with parameters using postman , I am always getting None for email,password, name and other variables

@csrf_exempt
def signup(request):
    if request.method != 'POST':
        raise Http404
    email = request.POST.get('email')
    password = request.POST.get('password')
    name = request.POST.get('name')
    os = request.POST.get('os')
    device_id = request.POST.get('device_id')
    version = request.POST.get('version')
    device = request.POST.get('device')
    print "email value is = %s", email
    user=AppUser.objects.get_or_create(email=password,password=password)
    user.save()
    return HttpResponse(json.dumps({"result": True}), content_type='application/json')

Please help , Why it is always showing None even though I am passing values from POST request for email and for other parameters

Below is the body request from post man using POST

http://127.0.0.1:8000/v1.0/signup/?email=nagu@nagu.com&password=nagendra&name=nagendra&os=android&device_id=12345678&version=23.0.1&device=samsung

below postman screen shot

在这里输入图像描述


The parameters you added to the url are GET parameters not POST parameters. POST parameters are in the request body and not visible through urls. Even you specify your request method is POST with your original url, you are not going to send any data.

If you in your commandline do something like:

curl --data "email=nagu@nagu.com&password=nagendra&name=nagendra&os=android&device_id=12345678&version=23.0.1&device=samsung" http://127.0.0.1:8000/v1.0/signup/

It should send POST data to your view.

Take a look at this SO question and answer on how POST requests are delivered.


I have tried postman in chrome. Below is the screenshot. Does this work for you?

邮递员在镀铬物


please make sure your parameter of body in postman is correct, it should be "x-www-form-urlencoded". THKS!

链接地址: http://www.djcxy.com/p/41338.html

上一篇: 如何通过HTTP连接从delphi客户端接收来自php服务器的数据?

下一篇: request.POST.get()总是返回None