Django REST Framework not generating form in Browsable API
Ok, I have a GenericAPIView
that is supposed to generate a form in the Browsable API cause it declares a post
method:
from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from transacciones.serializers import BillSerializer
class ProcessBill(GenericAPIView):
serializer_class = BillSerializer
def post(self, request):
recieved_data = request.data
print(recieved_data)
return Response("Processed Bill", status=status.HTTP_200_OK)
But it doesn't generate a form. The view looks like this (it is in spanish, I translated the code to english so it is be more confortable to read):
I understand I get a 405 Method not Allowed
cause I don't define a get
method, only a post
.
Im using Django 1.8, Django REST Framework 3.3.1 and python 3.4. I'm lost here. Any ideas?
EDIT
Also, if I use Postman (Chrome add on) the view responds correctly.
django django-rest-framework
|
show 2 more comments
Ok, I have a GenericAPIView
that is supposed to generate a form in the Browsable API cause it declares a post
method:
from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from transacciones.serializers import BillSerializer
class ProcessBill(GenericAPIView):
serializer_class = BillSerializer
def post(self, request):
recieved_data = request.data
print(recieved_data)
return Response("Processed Bill", status=status.HTTP_200_OK)
But it doesn't generate a form. The view looks like this (it is in spanish, I translated the code to english so it is be more confortable to read):
I understand I get a 405 Method not Allowed
cause I don't define a get
method, only a post
.
Im using Django 1.8, Django REST Framework 3.3.1 and python 3.4. I'm lost here. Any ideas?
EDIT
Also, if I use Postman (Chrome add on) the view responds correctly.
django django-rest-framework
1
Possible duplicate of Django Rest Framework how to post data on the browsable API
– Geotob
Dec 17 '15 at 20:28
@Geotob This question uses aGenericAPIView
, the old one uses aAPIView
. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…
– Alejandro Veintimilla
Dec 17 '15 at 20:34
Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.
– Alejandro Veintimilla
Dec 17 '15 at 20:35
Sorry I didn't spot this! :(GenericAPIViews
use acreate(request, *args, **kwargs)
method, notpost
– Geotob
Dec 17 '15 at 20:38
@Geotob tried the create method, doesn't work. Anyway,GenericAPIView
extends from theAPIView
, that what the docs say ... so it should have apost
method.
– Alejandro Veintimilla
Dec 17 '15 at 20:47
|
show 2 more comments
Ok, I have a GenericAPIView
that is supposed to generate a form in the Browsable API cause it declares a post
method:
from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from transacciones.serializers import BillSerializer
class ProcessBill(GenericAPIView):
serializer_class = BillSerializer
def post(self, request):
recieved_data = request.data
print(recieved_data)
return Response("Processed Bill", status=status.HTTP_200_OK)
But it doesn't generate a form. The view looks like this (it is in spanish, I translated the code to english so it is be more confortable to read):
I understand I get a 405 Method not Allowed
cause I don't define a get
method, only a post
.
Im using Django 1.8, Django REST Framework 3.3.1 and python 3.4. I'm lost here. Any ideas?
EDIT
Also, if I use Postman (Chrome add on) the view responds correctly.
django django-rest-framework
Ok, I have a GenericAPIView
that is supposed to generate a form in the Browsable API cause it declares a post
method:
from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from transacciones.serializers import BillSerializer
class ProcessBill(GenericAPIView):
serializer_class = BillSerializer
def post(self, request):
recieved_data = request.data
print(recieved_data)
return Response("Processed Bill", status=status.HTTP_200_OK)
But it doesn't generate a form. The view looks like this (it is in spanish, I translated the code to english so it is be more confortable to read):
I understand I get a 405 Method not Allowed
cause I don't define a get
method, only a post
.
Im using Django 1.8, Django REST Framework 3.3.1 and python 3.4. I'm lost here. Any ideas?
EDIT
Also, if I use Postman (Chrome add on) the view responds correctly.
django django-rest-framework
django django-rest-framework
edited Dec 17 '15 at 21:03
Alejandro Veintimilla
asked Dec 17 '15 at 20:26
Alejandro VeintimillaAlejandro Veintimilla
2,442741102
2,442741102
1
Possible duplicate of Django Rest Framework how to post data on the browsable API
– Geotob
Dec 17 '15 at 20:28
@Geotob This question uses aGenericAPIView
, the old one uses aAPIView
. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…
– Alejandro Veintimilla
Dec 17 '15 at 20:34
Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.
– Alejandro Veintimilla
Dec 17 '15 at 20:35
Sorry I didn't spot this! :(GenericAPIViews
use acreate(request, *args, **kwargs)
method, notpost
– Geotob
Dec 17 '15 at 20:38
@Geotob tried the create method, doesn't work. Anyway,GenericAPIView
extends from theAPIView
, that what the docs say ... so it should have apost
method.
– Alejandro Veintimilla
Dec 17 '15 at 20:47
|
show 2 more comments
1
Possible duplicate of Django Rest Framework how to post data on the browsable API
– Geotob
Dec 17 '15 at 20:28
@Geotob This question uses aGenericAPIView
, the old one uses aAPIView
. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…
– Alejandro Veintimilla
Dec 17 '15 at 20:34
Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.
– Alejandro Veintimilla
Dec 17 '15 at 20:35
Sorry I didn't spot this! :(GenericAPIViews
use acreate(request, *args, **kwargs)
method, notpost
– Geotob
Dec 17 '15 at 20:38
@Geotob tried the create method, doesn't work. Anyway,GenericAPIView
extends from theAPIView
, that what the docs say ... so it should have apost
method.
– Alejandro Veintimilla
Dec 17 '15 at 20:47
1
1
Possible duplicate of Django Rest Framework how to post data on the browsable API
– Geotob
Dec 17 '15 at 20:28
Possible duplicate of Django Rest Framework how to post data on the browsable API
– Geotob
Dec 17 '15 at 20:28
@Geotob This question uses a
GenericAPIView
, the old one uses a APIView
. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…– Alejandro Veintimilla
Dec 17 '15 at 20:34
@Geotob This question uses a
GenericAPIView
, the old one uses a APIView
. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…– Alejandro Veintimilla
Dec 17 '15 at 20:34
Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.
– Alejandro Veintimilla
Dec 17 '15 at 20:35
Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.
– Alejandro Veintimilla
Dec 17 '15 at 20:35
Sorry I didn't spot this! :(
GenericAPIViews
use a create(request, *args, **kwargs)
method, not post
– Geotob
Dec 17 '15 at 20:38
Sorry I didn't spot this! :(
GenericAPIViews
use a create(request, *args, **kwargs)
method, not post
– Geotob
Dec 17 '15 at 20:38
@Geotob tried the create method, doesn't work. Anyway,
GenericAPIView
extends from the APIView
, that what the docs say ... so it should have a post
method.– Alejandro Veintimilla
Dec 17 '15 at 20:47
@Geotob tried the create method, doesn't work. Anyway,
GenericAPIView
extends from the APIView
, that what the docs say ... so it should have a post
method.– Alejandro Veintimilla
Dec 17 '15 at 20:47
|
show 2 more comments
4 Answers
4
active
oldest
votes
You can use this
from rest_framework.generics import CreateAPIView
from rest_framework.mixins import CreateModelMixin
from rest_framework.response import Response
from transacciones.serializers import BillSerializer
class ProcessBill(CreateModelMixin, GenericAPIView):
serializer_class = BillSerializer
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
def create(self, request, *args, **kwargs):
# Do whatever you want here
# Then invoke the create method and create your instance
return super().create(request, *args, **kwargs)
Or as an alternative, you just inherit from CreateAPIView
which does essentially the same as the code above :)
Thanks for the answer. It doesn't work. : /
– Alejandro Veintimilla
Dec 17 '15 at 20:49
hm yea @alejoss i didn't notice that generics need thepost
method.. too used to viewsets. learned something new:) see the edit above, works fine for me
– Geotob
Dec 17 '15 at 21:20
add a comment |
If you are using generics.RetrieveUpdateDestroyAPIView
then you will have to define permission_classes which can be custom.
class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( checkUserPermission, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer
OR If you want to just test this, use permission_classes = ( AllowAny, )
class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( AllowAny, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer
add a comment |
I had the same issue, with postman I saw it was a credential issue, so changing current user status to staff solved the problem.
add a comment |
I ran into the same problem. In my case, the mistake was in the serializer, where I used django.db.models.CharField(...)
instead of rest_framework.serializers.CharField(...)
.
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%2f34343638%2fdjango-rest-framework-not-generating-form-in-browsable-api%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
You can use this
from rest_framework.generics import CreateAPIView
from rest_framework.mixins import CreateModelMixin
from rest_framework.response import Response
from transacciones.serializers import BillSerializer
class ProcessBill(CreateModelMixin, GenericAPIView):
serializer_class = BillSerializer
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
def create(self, request, *args, **kwargs):
# Do whatever you want here
# Then invoke the create method and create your instance
return super().create(request, *args, **kwargs)
Or as an alternative, you just inherit from CreateAPIView
which does essentially the same as the code above :)
Thanks for the answer. It doesn't work. : /
– Alejandro Veintimilla
Dec 17 '15 at 20:49
hm yea @alejoss i didn't notice that generics need thepost
method.. too used to viewsets. learned something new:) see the edit above, works fine for me
– Geotob
Dec 17 '15 at 21:20
add a comment |
You can use this
from rest_framework.generics import CreateAPIView
from rest_framework.mixins import CreateModelMixin
from rest_framework.response import Response
from transacciones.serializers import BillSerializer
class ProcessBill(CreateModelMixin, GenericAPIView):
serializer_class = BillSerializer
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
def create(self, request, *args, **kwargs):
# Do whatever you want here
# Then invoke the create method and create your instance
return super().create(request, *args, **kwargs)
Or as an alternative, you just inherit from CreateAPIView
which does essentially the same as the code above :)
Thanks for the answer. It doesn't work. : /
– Alejandro Veintimilla
Dec 17 '15 at 20:49
hm yea @alejoss i didn't notice that generics need thepost
method.. too used to viewsets. learned something new:) see the edit above, works fine for me
– Geotob
Dec 17 '15 at 21:20
add a comment |
You can use this
from rest_framework.generics import CreateAPIView
from rest_framework.mixins import CreateModelMixin
from rest_framework.response import Response
from transacciones.serializers import BillSerializer
class ProcessBill(CreateModelMixin, GenericAPIView):
serializer_class = BillSerializer
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
def create(self, request, *args, **kwargs):
# Do whatever you want here
# Then invoke the create method and create your instance
return super().create(request, *args, **kwargs)
Or as an alternative, you just inherit from CreateAPIView
which does essentially the same as the code above :)
You can use this
from rest_framework.generics import CreateAPIView
from rest_framework.mixins import CreateModelMixin
from rest_framework.response import Response
from transacciones.serializers import BillSerializer
class ProcessBill(CreateModelMixin, GenericAPIView):
serializer_class = BillSerializer
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
def create(self, request, *args, **kwargs):
# Do whatever you want here
# Then invoke the create method and create your instance
return super().create(request, *args, **kwargs)
Or as an alternative, you just inherit from CreateAPIView
which does essentially the same as the code above :)
edited Dec 17 '15 at 21:19
answered Dec 17 '15 at 20:42
GeotobGeotob
1,670714
1,670714
Thanks for the answer. It doesn't work. : /
– Alejandro Veintimilla
Dec 17 '15 at 20:49
hm yea @alejoss i didn't notice that generics need thepost
method.. too used to viewsets. learned something new:) see the edit above, works fine for me
– Geotob
Dec 17 '15 at 21:20
add a comment |
Thanks for the answer. It doesn't work. : /
– Alejandro Veintimilla
Dec 17 '15 at 20:49
hm yea @alejoss i didn't notice that generics need thepost
method.. too used to viewsets. learned something new:) see the edit above, works fine for me
– Geotob
Dec 17 '15 at 21:20
Thanks for the answer. It doesn't work. : /
– Alejandro Veintimilla
Dec 17 '15 at 20:49
Thanks for the answer. It doesn't work. : /
– Alejandro Veintimilla
Dec 17 '15 at 20:49
hm yea @alejoss i didn't notice that generics need the
post
method.. too used to viewsets. learned something new:) see the edit above, works fine for me– Geotob
Dec 17 '15 at 21:20
hm yea @alejoss i didn't notice that generics need the
post
method.. too used to viewsets. learned something new:) see the edit above, works fine for me– Geotob
Dec 17 '15 at 21:20
add a comment |
If you are using generics.RetrieveUpdateDestroyAPIView
then you will have to define permission_classes which can be custom.
class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( checkUserPermission, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer
OR If you want to just test this, use permission_classes = ( AllowAny, )
class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( AllowAny, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer
add a comment |
If you are using generics.RetrieveUpdateDestroyAPIView
then you will have to define permission_classes which can be custom.
class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( checkUserPermission, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer
OR If you want to just test this, use permission_classes = ( AllowAny, )
class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( AllowAny, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer
add a comment |
If you are using generics.RetrieveUpdateDestroyAPIView
then you will have to define permission_classes which can be custom.
class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( checkUserPermission, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer
OR If you want to just test this, use permission_classes = ( AllowAny, )
class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( AllowAny, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer
If you are using generics.RetrieveUpdateDestroyAPIView
then you will have to define permission_classes which can be custom.
class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( checkUserPermission, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer
OR If you want to just test this, use permission_classes = ( AllowAny, )
class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( AllowAny, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer
answered Apr 10 '17 at 8:37
SuperNovaSuperNova
6,19523323
6,19523323
add a comment |
add a comment |
I had the same issue, with postman I saw it was a credential issue, so changing current user status to staff solved the problem.
add a comment |
I had the same issue, with postman I saw it was a credential issue, so changing current user status to staff solved the problem.
add a comment |
I had the same issue, with postman I saw it was a credential issue, so changing current user status to staff solved the problem.
I had the same issue, with postman I saw it was a credential issue, so changing current user status to staff solved the problem.
answered Dec 11 '17 at 5:58
Natiq VahabovNatiq Vahabov
412410
412410
add a comment |
add a comment |
I ran into the same problem. In my case, the mistake was in the serializer, where I used django.db.models.CharField(...)
instead of rest_framework.serializers.CharField(...)
.
add a comment |
I ran into the same problem. In my case, the mistake was in the serializer, where I used django.db.models.CharField(...)
instead of rest_framework.serializers.CharField(...)
.
add a comment |
I ran into the same problem. In my case, the mistake was in the serializer, where I used django.db.models.CharField(...)
instead of rest_framework.serializers.CharField(...)
.
I ran into the same problem. In my case, the mistake was in the serializer, where I used django.db.models.CharField(...)
instead of rest_framework.serializers.CharField(...)
.
answered Nov 28 '18 at 16:22
ArjenArjen
5491512
5491512
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.
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%2f34343638%2fdjango-rest-framework-not-generating-form-in-browsable-api%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
1
Possible duplicate of Django Rest Framework how to post data on the browsable API
– Geotob
Dec 17 '15 at 20:28
@Geotob This question uses a
GenericAPIView
, the old one uses aAPIView
. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…– Alejandro Veintimilla
Dec 17 '15 at 20:34
Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.
– Alejandro Veintimilla
Dec 17 '15 at 20:35
Sorry I didn't spot this! :(
GenericAPIViews
use acreate(request, *args, **kwargs)
method, notpost
– Geotob
Dec 17 '15 at 20:38
@Geotob tried the create method, doesn't work. Anyway,
GenericAPIView
extends from theAPIView
, that what the docs say ... so it should have apost
method.– Alejandro Veintimilla
Dec 17 '15 at 20:47