django-rest-framework

allow post requests in django REST framework

谁都会走 提交于 2021-02-09 11:11:07
问题 I am creating a simple rest api using django REST framework. I have successfully got the response by sending GET request to the api but since I want to send POST request, the django rest framework doesn't allow POST request by default. As in image(below) only GET,HEAD, OPTIONS are allowed but not the POST request The GET and POST methods inside of views.py from django.shortcuts import render from rest_framework.views import APIView from rest_framework.response import Response from profiles

How to use coreapi client with django rest framework?

杀马特。学长 韩版系。学妹 提交于 2021-02-08 23:44:27
问题 I've integrated django rest framework version 3.10 into an existing django 2.2 project, placing api root at /api . Now I'm trying to use coreapi cli client to upload some documents to the server. $ coreapi get http://localhost:8000/openapi <DownloadedFile '/root/.coreapi/downloads/openapi (4)', open 'rb'> $ coreapi get http://localhost:8000/api { "invoices": "http://localhost:8000/api/invoices/" } $ coreapi action invoices list Index ['invoices']['list'] did not reference a link. Key

How to use coreapi client with django rest framework?

戏子无情 提交于 2021-02-08 23:44:20
问题 I've integrated django rest framework version 3.10 into an existing django 2.2 project, placing api root at /api . Now I'm trying to use coreapi cli client to upload some documents to the server. $ coreapi get http://localhost:8000/openapi <DownloadedFile '/root/.coreapi/downloads/openapi (4)', open 'rb'> $ coreapi get http://localhost:8000/api { "invoices": "http://localhost:8000/api/invoices/" } $ coreapi action invoices list Index ['invoices']['list'] did not reference a link. Key

How to use coreapi client with django rest framework?

别来无恙 提交于 2021-02-08 23:40:24
问题 I've integrated django rest framework version 3.10 into an existing django 2.2 project, placing api root at /api . Now I'm trying to use coreapi cli client to upload some documents to the server. $ coreapi get http://localhost:8000/openapi <DownloadedFile '/root/.coreapi/downloads/openapi (4)', open 'rb'> $ coreapi get http://localhost:8000/api { "invoices": "http://localhost:8000/api/invoices/" } $ coreapi action invoices list Index ['invoices']['list'] did not reference a link. Key

No difference between PUT and PATCH in Django REST Framework

断了今生、忘了曾经 提交于 2021-02-08 14:59:25
问题 Here are my simple viewset and serializer classes: class UserSerializer(ModelSerializer): class Meta: model = User fields = ['id', 'email', 'first_name', 'last_name'] .... class UserViewSet(ModelViewSet): queryset = User.objects.all() serializer_class = UserSerializer Suppose I want to update only my user's first name. In that case, I should use PATCH {"first_name": "New First Name"} . But at the same time, it looks like that PUT {"first_name": "New First Name"} also works the same way,

Token authentication does not work in production on django rest framework

主宰稳场 提交于 2021-02-08 12:34:09
问题 I have this strange issue and I can't find why. I've build the API using django 1.7 and django rest framework and token auth for api authentication. All works fine on local host, but when I'm trying to call an API endpoint which requires authentication on production machine I'm getting 403 status code along with the following message: {"detail":"Authentication credentials were not provided."}. What I'm doing wrong? I'm sending the token in the headers as per documentation. Here's how my

Token authentication does not work in production on django rest framework

只愿长相守 提交于 2021-02-08 12:34:00
问题 I have this strange issue and I can't find why. I've build the API using django 1.7 and django rest framework and token auth for api authentication. All works fine on local host, but when I'm trying to call an API endpoint which requires authentication on production machine I'm getting 403 status code along with the following message: {"detail":"Authentication credentials were not provided."}. What I'm doing wrong? I'm sending the token in the headers as per documentation. Here's how my

django-rest-auth handling expired confirmation email

孤人 提交于 2021-02-08 12:11:48
问题 I am using django-rest-auth and django-allauth to handle user authentication in my rest api. When a user tries to verify their email after the link has expired, I get an unpleasant error page. Please, how can I display a better error page or send a message telling them it wasn't successful because the link had expired? 回答1: As far as I can understand, your error is coming from django-allauth , not from your project. Reason for the error is that you did not include allauth.url in your main

How to create permission for specific rules in Django Rest Framework?

别来无恙 提交于 2021-02-08 11:56:22
问题 I want to arrange permission like that each user can edit his own profile. Just super user can edit all profile. What I need to add permissions.py ? Thank you. views.py class UserViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, mixins.UpdateModelMixin, mixins.DestroyModelMixin, generics.GenericAPIView): queryset = User.objects.all() serializer_class = UserSerializer permission_classes = [IsAuthenticated] authentication_classes = (JSONWebTokenAuthentication, ) permissions.py class

How to create permission for specific rules in Django Rest Framework?

有些话、适合烂在心里 提交于 2021-02-08 11:55:57
问题 I want to arrange permission like that each user can edit his own profile. Just super user can edit all profile. What I need to add permissions.py ? Thank you. views.py class UserViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, mixins.UpdateModelMixin, mixins.DestroyModelMixin, generics.GenericAPIView): queryset = User.objects.all() serializer_class = UserSerializer permission_classes = [IsAuthenticated] authentication_classes = (JSONWebTokenAuthentication, ) permissions.py class