django-rest-framework

Django Rest Framework with easy-thumbnails

孤街醉人 提交于 2021-01-26 14:46:21
问题 With a normal ImageField, serializing the URL is simply image = serializers.ImageField() . What should it look like when using easy-thumbnails? So far, I've only found a function for getting the URL: Django easy_thumbnails accessing image URLs Using this in a serializer would require a SerializerMethodField, which is an unsatisfying solution. I'm looking for a solution that's as efficient/performant as practical, and on one line. 回答1: Best solution is probably to subclass serializers

How to generate a file upload (test) request with Django REST Framework's APIRequestFactory?

主宰稳场 提交于 2021-01-26 11:08:50
问题 I have developed an API (Python 3.5, Django 1.10, DRF 3.4.2) that uploads a video file to my media path when I request it from my UI. That part is working fine. I try to write a test for this feature but cannot get it to run successfully. #views.py import os from rest_framework import views, parsers, response from django.conf import settings class FileUploadView(views.APIView): parser_classes = (parsers.FileUploadParser,) def put(self, request, filename): file = request.data['file'] handle

How to generate a file upload (test) request with Django REST Framework's APIRequestFactory?

孤街醉人 提交于 2021-01-26 11:06:59
问题 I have developed an API (Python 3.5, Django 1.10, DRF 3.4.2) that uploads a video file to my media path when I request it from my UI. That part is working fine. I try to write a test for this feature but cannot get it to run successfully. #views.py import os from rest_framework import views, parsers, response from django.conf import settings class FileUploadView(views.APIView): parser_classes = (parsers.FileUploadParser,) def put(self, request, filename): file = request.data['file'] handle

How to generate a file upload (test) request with Django REST Framework's APIRequestFactory?

こ雲淡風輕ζ 提交于 2021-01-26 11:05:25
问题 I have developed an API (Python 3.5, Django 1.10, DRF 3.4.2) that uploads a video file to my media path when I request it from my UI. That part is working fine. I try to write a test for this feature but cannot get it to run successfully. #views.py import os from rest_framework import views, parsers, response from django.conf import settings class FileUploadView(views.APIView): parser_classes = (parsers.FileUploadParser,) def put(self, request, filename): file = request.data['file'] handle

How can I configure “HTTPS” schemes with the drf-yasg auto-generated swagger page?

南笙酒味 提交于 2021-01-26 11:01:11
问题 I know in a traditional swagger YAML file, we can define the schemes with: schemes: - http - https //OR schemes: [http, https] However, how can I do the same thing with auto-generated swagger page with the drf-yasg library? Now, the generated swagger page only contains HTTP schemes, but HTTPS is missing. I've tried set the DEFAULT_API_URL in setting.py to https://mybaseurl.com , but it seems not to be working. 回答1: There is a solution. When defining get_schema_view() in urls.py , use this

How to get URL Id inside serializers create method?

拟墨画扇 提交于 2021-01-24 11:37:12
问题 I have the following URL: url(r'^member/(?P<member_id>\d+_([\w-]+){22})/join/?$', views.ActivityJoinView.as_view(), name='member_join'), Within my DRF serializer create method I need to get access to member_id . I have tried this: class JoinListSerializer(serializers.ModelSerializer): class Meta: model = Join fields = ("id", ) def create(self, validated_data): print(self.context['request'].query_params) I've also tried validated_data.get('member_id', None) But still get bank/none! How can I

How to decode token and get back information for djangorestframework-jwt packagefor Django

孤人 提交于 2021-01-24 07:31:16
问题 I have started using djangorestframework-jwt package instead of PyJWT , I just could not know how to decode the incoming token (I know there is verify token methode).... All I need to know is how to decode the token and get back info encoded...... 回答1: May be its too late to answer, but we can decode jwt and get our payload back using jwt.decode from jwt module Assume that jwt token you get looks like and your encrypted payload lies in middle of the token { "token":

How to decode token and get back information for djangorestframework-jwt packagefor Django

最后都变了- 提交于 2021-01-24 07:28:04
问题 I have started using djangorestframework-jwt package instead of PyJWT , I just could not know how to decode the incoming token (I know there is verify token methode).... All I need to know is how to decode the token and get back info encoded...... 回答1: May be its too late to answer, but we can decode jwt and get our payload back using jwt.decode from jwt module Assume that jwt token you get looks like and your encrypted payload lies in middle of the token { "token":

DRF create method in viewset or in serializer

女生的网名这么多〃 提交于 2021-01-24 07:08:07
问题 What is the difference between customizing the "create" method in DRF viewset or customizing it in the serializer? I understand the serializer is responsible to deserialize the data, i.e. the way the data is presented in the POST query; however, I can also create objects in related fields in the serializer. #views.py def create(self, request): pass #serializer.py def create(self, validated_data): return Model.objects.create(**validated_data) When should I customize views/create vs. serializer

DRF create method in viewset or in serializer

放肆的年华 提交于 2021-01-24 07:07:09
问题 What is the difference between customizing the "create" method in DRF viewset or customizing it in the serializer? I understand the serializer is responsible to deserialize the data, i.e. the way the data is presented in the POST query; however, I can also create objects in related fields in the serializer. #views.py def create(self, request): pass #serializer.py def create(self, validated_data): return Model.objects.create(**validated_data) When should I customize views/create vs. serializer