Search code examples
pythondjangodjango-rest-frameworkdjango-rest-auth

How to Consume POST Rest API on Django Web? want to consume API of User registration in django and here is the code which i have done


In Views.py this the code in view.py def Save(request):

      if request.method == "POST":
            user=request.POST
            email=user.get("email")
            password=user.get("password")
            print "password",password
            display_name= request.POST.get('displayname')
            hometown = request.POST.get('hometown')
            gender = request.POST.get('radios')
            occupation= request.POST.get('occupation')
            services.post_register(email,password,display_name,gender)

in Service.py code is- service.py

def post_register(email,password,display_name,gender):
    postdata={'email':email,'password':password,'display_name':display_name,'gender':gender,'}

    response = requests.post('http://www.example.com/rest-auth/users/1/',
                    data=json.dumps(postdata))

afer running this i am getting response 415. thank you


Solution

  • 415 error code means that the media type is not supported. I think you can simply replace the json.dumps(postdata) by postdata. Looking at the requests library you don't need it:

    r = requests.post('http://httpbin.org/post', data = {'key':'value'})