python - When tested http POST with chrome POSTMAN, it doesn't work in django -


i use django 1.9.7 & python 3.5

i implement creating user mechanism , tried test postman(chrome application), doesn't work , shows belows:

forbidden (csrf cookie not set.): /timeline/user/create/ 

this code :

urls.py

from django.conf.urls import url from. import views  app_name = 'timeline' urlpatterns = [     # ex) /     url(r'^$', views.timeline_view, name='timeline_view'),      # ex) /user/create     url(r'^user/(?p<method>create)/$', views.user_view, name='user_view'), ] 

views.py

from django.contrib.auth import authenticate, login, logout django.shortcuts import render, httpresponse  timeline.models import *   def timeline_view(request):     return httpresponse('hello world')   def user_view(request, method):     if method == 'create' , request.method == 'post':         print("hi")         username = request.post.get('username')         username = request.post.get('username')         user = user.objects.create_user(username, password=password)         user.first_name = request.post.get('name','')         user.save()         profile = userprofile()         profile.user = user         profile.save()         return httpresponse('create success')     else:         return httpresponse('bad request', status=400) 

postman : enter image description here

i tried django csrf cookie not set think post past version.

you should put csrftoken in request headers.
after sending request via postman, @ response cookies section, take csrftoken value , put in headers section of request, this:
key:x-csrftoken
value: jsdh6c3vahglshleytjh2n957qcilqmb #your token value


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -