django-rest-framework

Adding claims to DRF simple JWT payload

旧时模样 提交于 2020-12-26 13:32:01
问题 Using djangorestframework_simplejwt library, when POST to a custom view #urls.py path('api/token/', MyTokenObtainPairView.as_view(), name='token_obtain'), #views.py class MyTokenObtainPairView(TokenObtainPairView): serializer_class = MyTokenObtainPairSerializer I'm able to get a the following access token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNTkwOTEwNjg0LCJqdGkiOiI3M2MxYmZkOWNmMGY0ZjI3OTY4MGY0ZjhlYjA1NDQ5NyIsInVzZXJfaWQiOjExfQ

Adding claims to DRF simple JWT payload

自古美人都是妖i 提交于 2020-12-26 13:27:07
问题 Using djangorestframework_simplejwt library, when POST to a custom view #urls.py path('api/token/', MyTokenObtainPairView.as_view(), name='token_obtain'), #views.py class MyTokenObtainPairView(TokenObtainPairView): serializer_class = MyTokenObtainPairSerializer I'm able to get a the following access token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNTkwOTEwNjg0LCJqdGkiOiI3M2MxYmZkOWNmMGY0ZjI3OTY4MGY0ZjhlYjA1NDQ5NyIsInVzZXJfaWQiOjExfQ

how to use Django filtered class data to 2 seperate view

被刻印的时光 ゝ 提交于 2020-12-26 04:26:40
问题 I am using Django filter and using it in normal view it is working as expected now I want to download the filtered data so for this I am writing one download view where I am trying to use the same FilterClass but no luck. It is giving me an ERROR( Exception Value: type object 'CTSFilter' has no attribute 'values_list' ). Can anyone please help/suggest how to use filtered queryset in filter class more than one view OR pass the data of filtered query to the download views. Please find my code.

Paginating a list returned by a ViewSet in Django Rest Framework

馋奶兔 提交于 2020-12-16 06:07:50
问题 I have created a ViewSet class with a overridden list method like this: from rest_framework.response import Response from rest_framework import viewsets class MyViewSet(views.ViewSet): def list(self, request): return Response([ {"id": 1}, {"id": 2}, ]) How do I paginate this response? In settings.py I've the following setup: REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'LinkHeaderPagination', 'PAGE_SIZE': 10 } And LinkHeaderPagination is built like this: from rest_framework import

Paginating a list returned by a ViewSet in Django Rest Framework

寵の児 提交于 2020-12-16 06:02:35
问题 I have created a ViewSet class with a overridden list method like this: from rest_framework.response import Response from rest_framework import viewsets class MyViewSet(views.ViewSet): def list(self, request): return Response([ {"id": 1}, {"id": 2}, ]) How do I paginate this response? In settings.py I've the following setup: REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'LinkHeaderPagination', 'PAGE_SIZE': 10 } And LinkHeaderPagination is built like this: from rest_framework import

Paginating a list returned by a ViewSet in Django Rest Framework

偶尔善良 提交于 2020-12-16 06:02:29
问题 I have created a ViewSet class with a overridden list method like this: from rest_framework.response import Response from rest_framework import viewsets class MyViewSet(views.ViewSet): def list(self, request): return Response([ {"id": 1}, {"id": 2}, ]) How do I paginate this response? In settings.py I've the following setup: REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'LinkHeaderPagination', 'PAGE_SIZE': 10 } And LinkHeaderPagination is built like this: from rest_framework import

How to test email confirmation?

你离开我真会死。 提交于 2020-12-15 08:41:30
问题 I'm trying to make a test for the email confirmation view with django-rest-auth. Here is what I have: def test_verify_email(self): # Verify email address username = 'userTest' payload = { 'email': 'test@example.com', 'password1': 'TestpassUltra1', 'password2': 'TestpassUltra1', 'username': username, } res = self.client.post(REGISTER_USER_URL, payload) self.assertEqual(res.status_code, status.HTTP_201_CREATED) user = get_user_model().objects.get(email='test@example.com') # TODO retrieve the

How to implement Redis Cache with Django Rest Framework?

我们两清 提交于 2020-12-15 08:00:34
问题 I need to implement Redis cache with my Django Rest Framework site. But when I do load test using cache_page decorator with a class it improves the request per second but an error occurs "'function' object has no attribute 'get_extra_actions'" Views.py @cache_page(CACHE_TTL) class ParameterViewSet(viewsets.ModelViewSet): """ Lists all the parameters present in the system. Can pass filter with parent set to null to get top level Parameters. """ permission_classes = (IsAuthenticated,) queryset

GET products and images from two Django models, by filtering the product name and accessing the database only once

☆樱花仙子☆ 提交于 2020-12-15 05:23:39
问题 I have two Django models for an eCommerce website: class Product(models.Model): name=models.CharField(max_length=300) description=models.CharField(max_length=10000) class Thumnbnail(models.Model): thumnbnail=models.ImageField(null=True) product=models.ForeignKey(Product, related_name='related_product', on_delete=models.CASCADE) The user will input some keywords, and I filter on the product names with that keyword, and show only those products. With every product, on the results page, I want

GET products and images from two Django models, by filtering the product name and accessing the database only once

女生的网名这么多〃 提交于 2020-12-15 05:23:23
问题 I have two Django models for an eCommerce website: class Product(models.Model): name=models.CharField(max_length=300) description=models.CharField(max_length=10000) class Thumnbnail(models.Model): thumnbnail=models.ImageField(null=True) product=models.ForeignKey(Product, related_name='related_product', on_delete=models.CASCADE) The user will input some keywords, and I filter on the product names with that keyword, and show only those products. With every product, on the results page, I want