django-rest-framework

Django Rest Framework Nested Serializers

感情迁移 提交于 2020-08-25 07:45:11
问题 I am currently having trouble executing two layered nesting with Django rest framework. I have read the DRF docs with nested relationships here http://www.django-rest-framework.org/api-guide/relations/ and have successfully done the first layer which is to show styles with many colors in JSON. Not sure how to chain another layer though. Any help would be appreciated. Thanks in advance! The current output looks like this: [{ "name": "AAA123", "colors": [ { "name": "White" } ] }, { "name":

How can I use pagination_class in django-rest-framework for my custom pagination class

偶尔善良 提交于 2020-08-24 05:43:22
问题 My pagination Class class ArticleListPagination(PageNumberPagination): page_size = 2 page_size_query_param = 'page_size' My Article View Class class Article(generics.GenericAPIView): queryset = Articles.objects.all() serializer_class = ArticlesSerializer pagination_class = ArticleListPagination def get(self, request): queryset = self.get_queryset() serializer = ArticlesSerializer(queryset, many=True) return Response(serializer.data, status=status.HTTP_200_OK) I am able to use custom

How can I use pagination_class in django-rest-framework for my custom pagination class

↘锁芯ラ 提交于 2020-08-24 05:42:30
问题 My pagination Class class ArticleListPagination(PageNumberPagination): page_size = 2 page_size_query_param = 'page_size' My Article View Class class Article(generics.GenericAPIView): queryset = Articles.objects.all() serializer_class = ArticlesSerializer pagination_class = ArticleListPagination def get(self, request): queryset = self.get_queryset() serializer = ArticlesSerializer(queryset, many=True) return Response(serializer.data, status=status.HTTP_200_OK) I am able to use custom

Bulk, partial updates with Django Rest Framework

放肆的年华 提交于 2020-08-23 08:31:07
问题 I want to partially-update multiple items at once. I've already added a mixin for allowing me to bulk-create (and that works well) but even though I've added a partial argument, it doesn't allow for patching a list. I'm guessing that this is a routing issue. I need a new view to handle PATCH on / (rather than /id/ ), but I'm well out of my depth. Existing answers for this don't work for 3.8, or at least haven't worked for me. What do I need to do to the following? class ResourceSerializer

Difference between APIView class and viewsets class?

时光毁灭记忆、已成空白 提交于 2020-08-21 05:57:29
问题 What are the difference between APIView class and viewsets class ? I am following Django REST-framework official documentation. I think it lack examples. Can you explain the above difference with a suitable example. 回答1: APIView is the most basic class that you usually override when defining your REST view. You usually define your methods like get, put, delete and others check (http://www.cdrf.co/3.5/rest_framework.views/APIView.html). With APIView you define your view and you add it to your

“error”: “invalid_client” django-oauth-toolkit

对着背影说爱祢 提交于 2020-08-11 04:19:21
问题 I am using django rest framework with django-oauth-toolkit. When i request access token on my localhost it gives me the access token as shown below ~/django_app$ curl -X POST -d "grant_type=password&username=<Your-username>&password=<your-password>" -u"<client-id>:<client-secret>" http://localhost:8000/o/token/ {"access_token": "8u92BMmeZxvto244CE0eNHdLYWhWSa", "expires_in": 36000, "refresh_token": "faW06KKK71ZN74bx32KchMXGn8yjpV", "scope": "read write", "token_type": "Bearer"} But when i

“error”: “invalid_client” django-oauth-toolkit

拈花ヽ惹草 提交于 2020-08-11 04:19:08
问题 I am using django rest framework with django-oauth-toolkit. When i request access token on my localhost it gives me the access token as shown below ~/django_app$ curl -X POST -d "grant_type=password&username=<Your-username>&password=<your-password>" -u"<client-id>:<client-secret>" http://localhost:8000/o/token/ {"access_token": "8u92BMmeZxvto244CE0eNHdLYWhWSa", "expires_in": 36000, "refresh_token": "faW06KKK71ZN74bx32KchMXGn8yjpV", "scope": "read write", "token_type": "Bearer"} But when i

How can i trigger a Python script in background from HTML tag button, in Django?

喜你入骨 提交于 2020-08-11 02:51:42
问题 Please, how can i run a python script from my Django platform? I have a custom html page and i have a button tag ( <button></button> ) from which i would like to trigger the python code I've written on PDF's (wonderful parser). Actually, if the user of this app clicks on this parse it button, it triggers my python script stored in my static folder, and prints back the extracted texts and images in the table below: I greatly need your helps and possible ideas. Thanks before ! 回答1: Just add the

How can i trigger a Python script in background from HTML tag button, in Django?

家住魔仙堡 提交于 2020-08-11 02:51:33
问题 Please, how can i run a python script from my Django platform? I have a custom html page and i have a button tag ( <button></button> ) from which i would like to trigger the python code I've written on PDF's (wonderful parser). Actually, if the user of this app clicks on this parse it button, it triggers my python script stored in my static folder, and prints back the extracted texts and images in the table below: I greatly need your helps and possible ideas. Thanks before ! 回答1: Just add the

Change int value to .00 format

瘦欲@ 提交于 2020-08-10 20:28:27
问题 I have a dataframe - year month type amount 0 2019 9 Not Applicable 8000.00 1 2019 10 Not Applicable 7500.00 2 2019 11 Goods & Services 14000.35 3 2019 11 Not Applicable 7500.00 4 2019 12 Goods & Services 10499.00 5 2019 12 Not Applicable 9801.00 I have column amount fully round of but I want to convert another column month to this format like this - year month type amount 0 2019 9.00 Not Applicable 8000.00 1 2019 10.00 Not Applicable 7500.00 2 2019 11.00 Goods & Services 14000.35 3 2019 11