django-rest-framework

Call view from another view

我怕爱的太早我们不能终老 提交于 2021-02-20 04:07:45
问题 I have a viewset with one of the views as: @list_route(methods=["get"], url_path="special") def special(): pass And I call this view from another view like: view_fn = viewset.as_view({'get': 'list'}) response = view_fn(request) But it does not call my special function which maps to "/special/" , instead it calls the function which maps to "/" . I guess I need to pass url_path somehow or get the view using view name ? However, I'm not sure how to do either. 回答1: This will not work because you

Django Rest Framework - how to write multiple nested field serializer (for reading & writing)

倾然丶 夕夏残阳落幕 提交于 2021-02-19 08:33:58
问题 I'm trying to write a "def create" method to perform nested serialization for multiple objects. def create(self, validated_data): suggested_songs_data = validated_data.pop('suggested_songs') suggest_song_list = list() for song_data in suggested_songs_data: song = Song.objects.create(**song_data) suggest_song_list.append(song) message = Messages.objects.create(suggested_songs=suggest_song_list, **validated_data) return message Here is my schema: class MessagesSerializer(serializers

Django Rest Framework - how to write multiple nested field serializer (for reading & writing)

二次信任 提交于 2021-02-19 08:33:54
问题 I'm trying to write a "def create" method to perform nested serialization for multiple objects. def create(self, validated_data): suggested_songs_data = validated_data.pop('suggested_songs') suggest_song_list = list() for song_data in suggested_songs_data: song = Song.objects.create(**song_data) suggest_song_list.append(song) message = Messages.objects.create(suggested_songs=suggest_song_list, **validated_data) return message Here is my schema: class MessagesSerializer(serializers

customize error message in django rest

点点圈 提交于 2021-02-19 07:31:51
问题 i want to customize the error response from django rest framework. this is slandered error response from django rest.. { "style": [ "This field is required." ], "code": [ "code must be in 60 to 120 chars." ] } i want to customize it like.... { "style": [ "error_code":"20" "error_message":"This field is required." ], "code": [ "error_code":"22" "error_message":"code must be in 60 to 120 chars." ] } 回答1: I had the same problem in showing errors. First of all you should know that you can't use

customize error message in django rest

时光总嘲笑我的痴心妄想 提交于 2021-02-19 07:31:17
问题 i want to customize the error response from django rest framework. this is slandered error response from django rest.. { "style": [ "This field is required." ], "code": [ "code must be in 60 to 120 chars." ] } i want to customize it like.... { "style": [ "error_code":"20" "error_message":"This field is required." ], "code": [ "error_code":"22" "error_message":"code must be in 60 to 120 chars." ] } 回答1: I had the same problem in showing errors. First of all you should know that you can't use

Djoser for DRF with Knox tokens

十年热恋 提交于 2021-02-19 05:21:29
问题 I'm trying to use djoser with token authentication, but using django-rest-knox tokens. I have set the TOKEN_MODEL to knox.models.AuthToken , and the rest framework's DEFAULT_AUTHENTICATION_CLASSES to knox.auth.TokenAuthentication . I naïvely thought that this would be enough, but it seems that Djoser's inbuilt serializers (create token, and token), don't work properly with the knox tokens. I tried overriding them with custom serializers, but I didn't get anywhere (which is not to say it's not

Djoser for DRF with Knox tokens

别来无恙 提交于 2021-02-19 05:21:28
问题 I'm trying to use djoser with token authentication, but using django-rest-knox tokens. I have set the TOKEN_MODEL to knox.models.AuthToken , and the rest framework's DEFAULT_AUTHENTICATION_CLASSES to knox.auth.TokenAuthentication . I naïvely thought that this would be enough, but it seems that Djoser's inbuilt serializers (create token, and token), don't work properly with the knox tokens. I tried overriding them with custom serializers, but I didn't get anywhere (which is not to say it's not

Djoser for DRF with Knox tokens

柔情痞子 提交于 2021-02-19 05:21:11
问题 I'm trying to use djoser with token authentication, but using django-rest-knox tokens. I have set the TOKEN_MODEL to knox.models.AuthToken , and the rest framework's DEFAULT_AUTHENTICATION_CLASSES to knox.auth.TokenAuthentication . I naïvely thought that this would be enough, but it seems that Djoser's inbuilt serializers (create token, and token), don't work properly with the knox tokens. I tried overriding them with custom serializers, but I didn't get anywhere (which is not to say it's not

Djoser for DRF with Knox tokens

萝らか妹 提交于 2021-02-19 05:20:13
问题 I'm trying to use djoser with token authentication, but using django-rest-knox tokens. I have set the TOKEN_MODEL to knox.models.AuthToken , and the rest framework's DEFAULT_AUTHENTICATION_CLASSES to knox.auth.TokenAuthentication . I naïvely thought that this would be enough, but it seems that Djoser's inbuilt serializers (create token, and token), don't work properly with the knox tokens. I tried overriding them with custom serializers, but I didn't get anywhere (which is not to say it's not

`basename` argument not specified, and could ' \

£可爱£侵袭症+ 提交于 2021-02-19 04:53:10
问题 I am getting the below error again and again.I am trying to solve it from morning but nothing is happening. assert queryset is not None, ' basename argument not specified, and could ' \ AssertionError: basename argument not specified, and could not automatically determine the name from the viewset, as it does not have a .queryset attribute. models.py class Language(models.Model): A = models.CharField(max_length=50) B = models.ForeignKey(User,on_delete=models.CASCADE,null=True) C = models