Run django api from postman: CSRF verification failed
I'm trying to run an api using postman
. My application is developed in django 1.11.6
using python 3.5
.
My app is installed on an ubuntu
server. I have no login mechanism to create a csrf
token.
These are the steps that I follow:
- Click on "import" tab on the upper left side.
- Select the Raw Text option and paste my
cURL
command. - Hit import and I have the command in your Postman builder
- Press send button.
My curl
command is:
curl -i -H 'Accept: application/json; indent=4' -X POST https://127.0.0.1/users/:register/ -d "id=111&firstname=zinonas&yearofbirth=2007&lastname=Antoniou&othernames="
The error I get is Forbidden (403) - CSRF verification failed. Request aborted
.
When I run the curl command
via cygwin
, it's working properly.
This is the view function that I'm using:
class ApiUserRegister(APIView):
permission_classes = ()
serializer_class = RegisterUserSerializer
def post(self, request):
serializer = RegisterUserSerializer(data=request.data)
# Check format and unique constraint
serializer.is_valid(raise_exception=True)
data = serializer.data
if User.objects.filter(id=data['id']).exists():
user = User.objects.get(id=data['id'])
is_new = "false"
resp_status = status.HTTP_200_OK
else:
user = User.objects.create(id=data['id'],
firstname=data['firstname'],
yearofbirth=data['yearofbirth'],
lastname=data['lastname'],
othernames=data['othernames'])
user.save()
is_new = "true"
resp_status = status.HTTP_201_CREATED
resp = {"user": serializer.get_serialized(user),
"isnew": is_new}
return Response(resp, status=resp_status)
In settings.py
I have:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
)
}
python django curl
|
show 2 more comments
I'm trying to run an api using postman
. My application is developed in django 1.11.6
using python 3.5
.
My app is installed on an ubuntu
server. I have no login mechanism to create a csrf
token.
These are the steps that I follow:
- Click on "import" tab on the upper left side.
- Select the Raw Text option and paste my
cURL
command. - Hit import and I have the command in your Postman builder
- Press send button.
My curl
command is:
curl -i -H 'Accept: application/json; indent=4' -X POST https://127.0.0.1/users/:register/ -d "id=111&firstname=zinonas&yearofbirth=2007&lastname=Antoniou&othernames="
The error I get is Forbidden (403) - CSRF verification failed. Request aborted
.
When I run the curl command
via cygwin
, it's working properly.
This is the view function that I'm using:
class ApiUserRegister(APIView):
permission_classes = ()
serializer_class = RegisterUserSerializer
def post(self, request):
serializer = RegisterUserSerializer(data=request.data)
# Check format and unique constraint
serializer.is_valid(raise_exception=True)
data = serializer.data
if User.objects.filter(id=data['id']).exists():
user = User.objects.get(id=data['id'])
is_new = "false"
resp_status = status.HTTP_200_OK
else:
user = User.objects.create(id=data['id'],
firstname=data['firstname'],
yearofbirth=data['yearofbirth'],
lastname=data['lastname'],
othernames=data['othernames'])
user.save()
is_new = "true"
resp_status = status.HTTP_201_CREATED
resp = {"user": serializer.get_serialized(user),
"isnew": is_new}
return Response(resp, status=resp_status)
In settings.py
I have:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
)
}
python django curl
where is the view that you are trying to get?
– mohammed qudah
Oct 25 '17 at 7:20
@mohammedqudah It's a view to register a new user. I've added it to my question.
– zinon
Oct 25 '17 at 7:22
In your curl command, your url does not look good as it contains:
.
– aquaman
Oct 25 '17 at 8:03
@aquaman Yes, I want to have this character in my api.
– zinon
Oct 25 '17 at 8:04
Also if you are requestinghttps
you should use something likecurl -k ...
– aquaman
Oct 25 '17 at 8:07
|
show 2 more comments
I'm trying to run an api using postman
. My application is developed in django 1.11.6
using python 3.5
.
My app is installed on an ubuntu
server. I have no login mechanism to create a csrf
token.
These are the steps that I follow:
- Click on "import" tab on the upper left side.
- Select the Raw Text option and paste my
cURL
command. - Hit import and I have the command in your Postman builder
- Press send button.
My curl
command is:
curl -i -H 'Accept: application/json; indent=4' -X POST https://127.0.0.1/users/:register/ -d "id=111&firstname=zinonas&yearofbirth=2007&lastname=Antoniou&othernames="
The error I get is Forbidden (403) - CSRF verification failed. Request aborted
.
When I run the curl command
via cygwin
, it's working properly.
This is the view function that I'm using:
class ApiUserRegister(APIView):
permission_classes = ()
serializer_class = RegisterUserSerializer
def post(self, request):
serializer = RegisterUserSerializer(data=request.data)
# Check format and unique constraint
serializer.is_valid(raise_exception=True)
data = serializer.data
if User.objects.filter(id=data['id']).exists():
user = User.objects.get(id=data['id'])
is_new = "false"
resp_status = status.HTTP_200_OK
else:
user = User.objects.create(id=data['id'],
firstname=data['firstname'],
yearofbirth=data['yearofbirth'],
lastname=data['lastname'],
othernames=data['othernames'])
user.save()
is_new = "true"
resp_status = status.HTTP_201_CREATED
resp = {"user": serializer.get_serialized(user),
"isnew": is_new}
return Response(resp, status=resp_status)
In settings.py
I have:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
)
}
python django curl
I'm trying to run an api using postman
. My application is developed in django 1.11.6
using python 3.5
.
My app is installed on an ubuntu
server. I have no login mechanism to create a csrf
token.
These are the steps that I follow:
- Click on "import" tab on the upper left side.
- Select the Raw Text option and paste my
cURL
command. - Hit import and I have the command in your Postman builder
- Press send button.
My curl
command is:
curl -i -H 'Accept: application/json; indent=4' -X POST https://127.0.0.1/users/:register/ -d "id=111&firstname=zinonas&yearofbirth=2007&lastname=Antoniou&othernames="
The error I get is Forbidden (403) - CSRF verification failed. Request aborted
.
When I run the curl command
via cygwin
, it's working properly.
This is the view function that I'm using:
class ApiUserRegister(APIView):
permission_classes = ()
serializer_class = RegisterUserSerializer
def post(self, request):
serializer = RegisterUserSerializer(data=request.data)
# Check format and unique constraint
serializer.is_valid(raise_exception=True)
data = serializer.data
if User.objects.filter(id=data['id']).exists():
user = User.objects.get(id=data['id'])
is_new = "false"
resp_status = status.HTTP_200_OK
else:
user = User.objects.create(id=data['id'],
firstname=data['firstname'],
yearofbirth=data['yearofbirth'],
lastname=data['lastname'],
othernames=data['othernames'])
user.save()
is_new = "true"
resp_status = status.HTTP_201_CREATED
resp = {"user": serializer.get_serialized(user),
"isnew": is_new}
return Response(resp, status=resp_status)
In settings.py
I have:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
)
}
python django curl
python django curl
edited Oct 25 '17 at 13:43
asked Oct 25 '17 at 7:16
zinon
1,48942964
1,48942964
where is the view that you are trying to get?
– mohammed qudah
Oct 25 '17 at 7:20
@mohammedqudah It's a view to register a new user. I've added it to my question.
– zinon
Oct 25 '17 at 7:22
In your curl command, your url does not look good as it contains:
.
– aquaman
Oct 25 '17 at 8:03
@aquaman Yes, I want to have this character in my api.
– zinon
Oct 25 '17 at 8:04
Also if you are requestinghttps
you should use something likecurl -k ...
– aquaman
Oct 25 '17 at 8:07
|
show 2 more comments
where is the view that you are trying to get?
– mohammed qudah
Oct 25 '17 at 7:20
@mohammedqudah It's a view to register a new user. I've added it to my question.
– zinon
Oct 25 '17 at 7:22
In your curl command, your url does not look good as it contains:
.
– aquaman
Oct 25 '17 at 8:03
@aquaman Yes, I want to have this character in my api.
– zinon
Oct 25 '17 at 8:04
Also if you are requestinghttps
you should use something likecurl -k ...
– aquaman
Oct 25 '17 at 8:07
where is the view that you are trying to get?
– mohammed qudah
Oct 25 '17 at 7:20
where is the view that you are trying to get?
– mohammed qudah
Oct 25 '17 at 7:20
@mohammedqudah It's a view to register a new user. I've added it to my question.
– zinon
Oct 25 '17 at 7:22
@mohammedqudah It's a view to register a new user. I've added it to my question.
– zinon
Oct 25 '17 at 7:22
In your curl command, your url does not look good as it contains
:
.– aquaman
Oct 25 '17 at 8:03
In your curl command, your url does not look good as it contains
:
.– aquaman
Oct 25 '17 at 8:03
@aquaman Yes, I want to have this character in my api.
– zinon
Oct 25 '17 at 8:04
@aquaman Yes, I want to have this character in my api.
– zinon
Oct 25 '17 at 8:04
Also if you are requesting
https
you should use something like curl -k ...
– aquaman
Oct 25 '17 at 8:07
Also if you are requesting
https
you should use something like curl -k ...
– aquaman
Oct 25 '17 at 8:07
|
show 2 more comments
4 Answers
4
active
oldest
votes
To make AJAX requests, you need to include CSRF token in the HTTP header, as described in the Django documentation.
1st option
2nd option
I'm not usingjQuery
. I created an API to using via `android' app.
– zinon
Oct 25 '17 at 7:51
Can you please give me an example?
– zinon
Oct 25 '17 at 8:03
1. get csrftoken cookie with safe GET query (view can use ensure_csrf_cookie decorator) 2. use csrftoken in new POST query
– LennyLip
Oct 25 '17 at 8:06
1
The answer does not address Postman, which is a key part of the question.
– BrianHVB
Nov 20 at 18:26
@BrianHVB Are you sure? Answer updated
– LennyLip
Nov 21 at 6:12
|
show 2 more comments
update your class to be like this
from braces.views import CsrfExemptMixin
class your_class(CsrfExemptMixin, ......yours_here)
def post(...):
[....]
this will tell django to allow requests without csrf
Using this I getname 'csrf_exempt' is not defined
error.
– zinon
Oct 25 '17 at 7:35
I get error'function' object has no attribute 'as_view'
.Inurls.py
I have this line:url(r':register/$', views.ApiUserRegister.as_view(), name='register-user')
– zinon
Oct 25 '17 at 7:41
No I get the errorThe keyword argument "name" must be the name of a method of the decorated class: <class 'users.views.ApiUserRegister'>. Got '' instead
– zinon
Oct 25 '17 at 7:46
Unfortunately, no. I set@method_decorator(csrf_exempt, name="post")
and now I get once againForbidden (403) CSRF verification failed. Request aborted.
– zinon
Oct 25 '17 at 7:50
Isbraces
a module that I can install usingpip3
?
– zinon
Oct 25 '17 at 7:56
|
show 6 more comments
Try this.
from django.views.decorators.csrf import csrf_exempt
class ApiUserRegister(APIView):
permission_classes = ()
serializer_class = RegisterUserSerializer
@csrf_exempt
def post(self, request):
serializer = RegisterUserSerializer(data=request.data)
I tried it butforbidden 403
error remains.
– zinon
Oct 25 '17 at 13:25
Refer this. stackoverflow.com/questions/12174040/…
– python_user
Oct 27 '17 at 7:34
I'm not using any template.
– zinon
Oct 27 '17 at 7:38
add a comment |
In urls file, try this:
urlpatterns = [
url(r'^your_uri/', views.YourView.as_view()),
]
this will tell django to allow requests without csrf
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46926227%2frun-django-api-from-postman-csrf-verification-failed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
To make AJAX requests, you need to include CSRF token in the HTTP header, as described in the Django documentation.
1st option
2nd option
I'm not usingjQuery
. I created an API to using via `android' app.
– zinon
Oct 25 '17 at 7:51
Can you please give me an example?
– zinon
Oct 25 '17 at 8:03
1. get csrftoken cookie with safe GET query (view can use ensure_csrf_cookie decorator) 2. use csrftoken in new POST query
– LennyLip
Oct 25 '17 at 8:06
1
The answer does not address Postman, which is a key part of the question.
– BrianHVB
Nov 20 at 18:26
@BrianHVB Are you sure? Answer updated
– LennyLip
Nov 21 at 6:12
|
show 2 more comments
To make AJAX requests, you need to include CSRF token in the HTTP header, as described in the Django documentation.
1st option
2nd option
I'm not usingjQuery
. I created an API to using via `android' app.
– zinon
Oct 25 '17 at 7:51
Can you please give me an example?
– zinon
Oct 25 '17 at 8:03
1. get csrftoken cookie with safe GET query (view can use ensure_csrf_cookie decorator) 2. use csrftoken in new POST query
– LennyLip
Oct 25 '17 at 8:06
1
The answer does not address Postman, which is a key part of the question.
– BrianHVB
Nov 20 at 18:26
@BrianHVB Are you sure? Answer updated
– LennyLip
Nov 21 at 6:12
|
show 2 more comments
To make AJAX requests, you need to include CSRF token in the HTTP header, as described in the Django documentation.
1st option
2nd option
To make AJAX requests, you need to include CSRF token in the HTTP header, as described in the Django documentation.
1st option
2nd option
edited Nov 21 at 6:12
answered Oct 25 '17 at 7:32
LennyLip
457612
457612
I'm not usingjQuery
. I created an API to using via `android' app.
– zinon
Oct 25 '17 at 7:51
Can you please give me an example?
– zinon
Oct 25 '17 at 8:03
1. get csrftoken cookie with safe GET query (view can use ensure_csrf_cookie decorator) 2. use csrftoken in new POST query
– LennyLip
Oct 25 '17 at 8:06
1
The answer does not address Postman, which is a key part of the question.
– BrianHVB
Nov 20 at 18:26
@BrianHVB Are you sure? Answer updated
– LennyLip
Nov 21 at 6:12
|
show 2 more comments
I'm not usingjQuery
. I created an API to using via `android' app.
– zinon
Oct 25 '17 at 7:51
Can you please give me an example?
– zinon
Oct 25 '17 at 8:03
1. get csrftoken cookie with safe GET query (view can use ensure_csrf_cookie decorator) 2. use csrftoken in new POST query
– LennyLip
Oct 25 '17 at 8:06
1
The answer does not address Postman, which is a key part of the question.
– BrianHVB
Nov 20 at 18:26
@BrianHVB Are you sure? Answer updated
– LennyLip
Nov 21 at 6:12
I'm not using
jQuery
. I created an API to using via `android' app.– zinon
Oct 25 '17 at 7:51
I'm not using
jQuery
. I created an API to using via `android' app.– zinon
Oct 25 '17 at 7:51
Can you please give me an example?
– zinon
Oct 25 '17 at 8:03
Can you please give me an example?
– zinon
Oct 25 '17 at 8:03
1. get csrftoken cookie with safe GET query (view can use ensure_csrf_cookie decorator) 2. use csrftoken in new POST query
– LennyLip
Oct 25 '17 at 8:06
1. get csrftoken cookie with safe GET query (view can use ensure_csrf_cookie decorator) 2. use csrftoken in new POST query
– LennyLip
Oct 25 '17 at 8:06
1
1
The answer does not address Postman, which is a key part of the question.
– BrianHVB
Nov 20 at 18:26
The answer does not address Postman, which is a key part of the question.
– BrianHVB
Nov 20 at 18:26
@BrianHVB Are you sure? Answer updated
– LennyLip
Nov 21 at 6:12
@BrianHVB Are you sure? Answer updated
– LennyLip
Nov 21 at 6:12
|
show 2 more comments
update your class to be like this
from braces.views import CsrfExemptMixin
class your_class(CsrfExemptMixin, ......yours_here)
def post(...):
[....]
this will tell django to allow requests without csrf
Using this I getname 'csrf_exempt' is not defined
error.
– zinon
Oct 25 '17 at 7:35
I get error'function' object has no attribute 'as_view'
.Inurls.py
I have this line:url(r':register/$', views.ApiUserRegister.as_view(), name='register-user')
– zinon
Oct 25 '17 at 7:41
No I get the errorThe keyword argument "name" must be the name of a method of the decorated class: <class 'users.views.ApiUserRegister'>. Got '' instead
– zinon
Oct 25 '17 at 7:46
Unfortunately, no. I set@method_decorator(csrf_exempt, name="post")
and now I get once againForbidden (403) CSRF verification failed. Request aborted.
– zinon
Oct 25 '17 at 7:50
Isbraces
a module that I can install usingpip3
?
– zinon
Oct 25 '17 at 7:56
|
show 6 more comments
update your class to be like this
from braces.views import CsrfExemptMixin
class your_class(CsrfExemptMixin, ......yours_here)
def post(...):
[....]
this will tell django to allow requests without csrf
Using this I getname 'csrf_exempt' is not defined
error.
– zinon
Oct 25 '17 at 7:35
I get error'function' object has no attribute 'as_view'
.Inurls.py
I have this line:url(r':register/$', views.ApiUserRegister.as_view(), name='register-user')
– zinon
Oct 25 '17 at 7:41
No I get the errorThe keyword argument "name" must be the name of a method of the decorated class: <class 'users.views.ApiUserRegister'>. Got '' instead
– zinon
Oct 25 '17 at 7:46
Unfortunately, no. I set@method_decorator(csrf_exempt, name="post")
and now I get once againForbidden (403) CSRF verification failed. Request aborted.
– zinon
Oct 25 '17 at 7:50
Isbraces
a module that I can install usingpip3
?
– zinon
Oct 25 '17 at 7:56
|
show 6 more comments
update your class to be like this
from braces.views import CsrfExemptMixin
class your_class(CsrfExemptMixin, ......yours_here)
def post(...):
[....]
this will tell django to allow requests without csrf
update your class to be like this
from braces.views import CsrfExemptMixin
class your_class(CsrfExemptMixin, ......yours_here)
def post(...):
[....]
this will tell django to allow requests without csrf
edited Oct 25 '17 at 7:55
answered Oct 25 '17 at 7:30
mohammed qudah
487313
487313
Using this I getname 'csrf_exempt' is not defined
error.
– zinon
Oct 25 '17 at 7:35
I get error'function' object has no attribute 'as_view'
.Inurls.py
I have this line:url(r':register/$', views.ApiUserRegister.as_view(), name='register-user')
– zinon
Oct 25 '17 at 7:41
No I get the errorThe keyword argument "name" must be the name of a method of the decorated class: <class 'users.views.ApiUserRegister'>. Got '' instead
– zinon
Oct 25 '17 at 7:46
Unfortunately, no. I set@method_decorator(csrf_exempt, name="post")
and now I get once againForbidden (403) CSRF verification failed. Request aborted.
– zinon
Oct 25 '17 at 7:50
Isbraces
a module that I can install usingpip3
?
– zinon
Oct 25 '17 at 7:56
|
show 6 more comments
Using this I getname 'csrf_exempt' is not defined
error.
– zinon
Oct 25 '17 at 7:35
I get error'function' object has no attribute 'as_view'
.Inurls.py
I have this line:url(r':register/$', views.ApiUserRegister.as_view(), name='register-user')
– zinon
Oct 25 '17 at 7:41
No I get the errorThe keyword argument "name" must be the name of a method of the decorated class: <class 'users.views.ApiUserRegister'>. Got '' instead
– zinon
Oct 25 '17 at 7:46
Unfortunately, no. I set@method_decorator(csrf_exempt, name="post")
and now I get once againForbidden (403) CSRF verification failed. Request aborted.
– zinon
Oct 25 '17 at 7:50
Isbraces
a module that I can install usingpip3
?
– zinon
Oct 25 '17 at 7:56
Using this I get
name 'csrf_exempt' is not defined
error.– zinon
Oct 25 '17 at 7:35
Using this I get
name 'csrf_exempt' is not defined
error.– zinon
Oct 25 '17 at 7:35
I get error
'function' object has no attribute 'as_view'
.In urls.py
I have this line: url(r':register/$', views.ApiUserRegister.as_view(), name='register-user')
– zinon
Oct 25 '17 at 7:41
I get error
'function' object has no attribute 'as_view'
.In urls.py
I have this line: url(r':register/$', views.ApiUserRegister.as_view(), name='register-user')
– zinon
Oct 25 '17 at 7:41
No I get the error
The keyword argument "name" must be the name of a method of the decorated class: <class 'users.views.ApiUserRegister'>. Got '' instead
– zinon
Oct 25 '17 at 7:46
No I get the error
The keyword argument "name" must be the name of a method of the decorated class: <class 'users.views.ApiUserRegister'>. Got '' instead
– zinon
Oct 25 '17 at 7:46
Unfortunately, no. I set
@method_decorator(csrf_exempt, name="post")
and now I get once again Forbidden (403) CSRF verification failed. Request aborted.
– zinon
Oct 25 '17 at 7:50
Unfortunately, no. I set
@method_decorator(csrf_exempt, name="post")
and now I get once again Forbidden (403) CSRF verification failed. Request aborted.
– zinon
Oct 25 '17 at 7:50
Is
braces
a module that I can install using pip3
?– zinon
Oct 25 '17 at 7:56
Is
braces
a module that I can install using pip3
?– zinon
Oct 25 '17 at 7:56
|
show 6 more comments
Try this.
from django.views.decorators.csrf import csrf_exempt
class ApiUserRegister(APIView):
permission_classes = ()
serializer_class = RegisterUserSerializer
@csrf_exempt
def post(self, request):
serializer = RegisterUserSerializer(data=request.data)
I tried it butforbidden 403
error remains.
– zinon
Oct 25 '17 at 13:25
Refer this. stackoverflow.com/questions/12174040/…
– python_user
Oct 27 '17 at 7:34
I'm not using any template.
– zinon
Oct 27 '17 at 7:38
add a comment |
Try this.
from django.views.decorators.csrf import csrf_exempt
class ApiUserRegister(APIView):
permission_classes = ()
serializer_class = RegisterUserSerializer
@csrf_exempt
def post(self, request):
serializer = RegisterUserSerializer(data=request.data)
I tried it butforbidden 403
error remains.
– zinon
Oct 25 '17 at 13:25
Refer this. stackoverflow.com/questions/12174040/…
– python_user
Oct 27 '17 at 7:34
I'm not using any template.
– zinon
Oct 27 '17 at 7:38
add a comment |
Try this.
from django.views.decorators.csrf import csrf_exempt
class ApiUserRegister(APIView):
permission_classes = ()
serializer_class = RegisterUserSerializer
@csrf_exempt
def post(self, request):
serializer = RegisterUserSerializer(data=request.data)
Try this.
from django.views.decorators.csrf import csrf_exempt
class ApiUserRegister(APIView):
permission_classes = ()
serializer_class = RegisterUserSerializer
@csrf_exempt
def post(self, request):
serializer = RegisterUserSerializer(data=request.data)
answered Oct 25 '17 at 12:15
python_user
114
114
I tried it butforbidden 403
error remains.
– zinon
Oct 25 '17 at 13:25
Refer this. stackoverflow.com/questions/12174040/…
– python_user
Oct 27 '17 at 7:34
I'm not using any template.
– zinon
Oct 27 '17 at 7:38
add a comment |
I tried it butforbidden 403
error remains.
– zinon
Oct 25 '17 at 13:25
Refer this. stackoverflow.com/questions/12174040/…
– python_user
Oct 27 '17 at 7:34
I'm not using any template.
– zinon
Oct 27 '17 at 7:38
I tried it but
forbidden 403
error remains.– zinon
Oct 25 '17 at 13:25
I tried it but
forbidden 403
error remains.– zinon
Oct 25 '17 at 13:25
Refer this. stackoverflow.com/questions/12174040/…
– python_user
Oct 27 '17 at 7:34
Refer this. stackoverflow.com/questions/12174040/…
– python_user
Oct 27 '17 at 7:34
I'm not using any template.
– zinon
Oct 27 '17 at 7:38
I'm not using any template.
– zinon
Oct 27 '17 at 7:38
add a comment |
In urls file, try this:
urlpatterns = [
url(r'^your_uri/', views.YourView.as_view()),
]
this will tell django to allow requests without csrf
add a comment |
In urls file, try this:
urlpatterns = [
url(r'^your_uri/', views.YourView.as_view()),
]
this will tell django to allow requests without csrf
add a comment |
In urls file, try this:
urlpatterns = [
url(r'^your_uri/', views.YourView.as_view()),
]
this will tell django to allow requests without csrf
In urls file, try this:
urlpatterns = [
url(r'^your_uri/', views.YourView.as_view()),
]
this will tell django to allow requests without csrf
answered Dec 10 at 10:38
TrungVK
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46926227%2frun-django-api-from-postman-csrf-verification-failed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
where is the view that you are trying to get?
– mohammed qudah
Oct 25 '17 at 7:20
@mohammedqudah It's a view to register a new user. I've added it to my question.
– zinon
Oct 25 '17 at 7:22
In your curl command, your url does not look good as it contains
:
.– aquaman
Oct 25 '17 at 8:03
@aquaman Yes, I want to have this character in my api.
– zinon
Oct 25 '17 at 8:04
Also if you are requesting
https
you should use something likecurl -k ...
– aquaman
Oct 25 '17 at 8:07