Django REST Framework (DRF): TypeError: register() got an unexpected keyword argument ‘base_name’

From the release notes of Django RestFramework and DRF 3.9 announcement they mentioned that Deprecate the Router.register base_name argument in favor of basename. #5990 Which means, the argument base_name is no longer available from DRF=3.11 onwards and use basename instead So, Change your router config as, router.register(r’musician’, MusicianViewset, basename=”musician”) router.register(r’album’, AlbumViewset, basename=”album”)

TypeError while using django rest framework tutorial

Just to let others know, I kept getting this same error and found that I forgot to include a comma in my REST_FRAMEWORK. I had this: ‘DEFAULT_PERMISSION_CLASSES’: ( ‘rest_framework.permissions.IsAuthenticated’ ), instead of this: ‘DEFAULT_PERMISSION_CLASSES’: ( ‘rest_framework.permissions.IsAuthenticated’, ), The comma defines this as a one-element tuple

Django-Rest-Framework 3.0 Field name ” is not valid for model `ModelBase`

The issue happens under urls.py‘s ‘fields’. Make sure that the fields in your serializer match exactly (case sensitive) to the field in your models.py. ### urls.py #… # Serializers define the API representation class CallTraceAttemptsSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = CallTraceAttempts fields = (‘calltraceattemptid’, ‘datecreated’) ### Issue was right here, earlier version had ‘Datecreated’

Creating multiple objects with one request in Django and Django Rest Framework

Init the serializer with many=True In your implementation this is really easy to accomplish: serialized = MovieTicketSerializer(data=request.data, many=True) Data is no single object but an array of objects. Your infos suggest that you need to transform request.data to make those multiple objects (all the same data just different seat number). Right? anyways: see: How do … Read more

Django REST framework object level permissions

I have done this in the past using a custom permission and overridden has_object_permission like the following: from rest_framework import permissions class MyUserPermissions(permissions.BasePermission): “”” Handles permissions for users. The basic rules are – owner may GET, PUT, POST, DELETE – nobody else can access “”” def has_object_permission(self, request, view, obj): # check if user is … Read more

integrate django password validators with django rest framework validate_password

Like you mentioned, when you validate the password in validate_password method using UserAttributeSimilarityValidator validator, you don’t have the user object. What I suggest that instead of doing field-level validation, you shall perform object-level validation by implementing validate method on the serializer: import sys from django.core import exceptions import django.contrib.auth.password_validation as validators class RegisterUserSerializer(serializers.ModelSerializer): # rest … Read more

Update/append serializer.data in Django Rest Framework [duplicate]

Unfortunately, serializer.data is a property of the class and therefore immutable. Instead of adding items to serializer.data you can copy serializer.data to another dict. You can try this: newdict={‘item’:”test”} newdict.update(serializer.data) return Response(newdict, status=status.HTTP_201_CREATED) Read more about property

How to dynamically remove fields from serializer output

You can customize the serialization behavior by overriding the to_representation() method in your serializer. class DynamicSerliazer(serializers.ModelSerializer): def to_representation(self, obj): # get the original representation ret = super(DynamicSerializer, self).to_representation(obj) # remove ‘url’ field if mobile request if is_mobile_platform(self.context.get(‘request’, None)): ret.pop(‘url’) # here write the logic to check whether `elements` field is to be removed # pop … Read more

get router url name when testing in Django Rest Framework

DRF adds suffixes in viewsets for different URLs – list, detail and possibly custom URLs. You can see that in source code and in docs. So in your case the actual reverse should be something like: reverse(‘api:my_list-list’) # for list URL. e.g. /api/my-list/ reverse(‘api:my_list-detail’) # for detail URL. e.g. /api/my-list/<pk>/ That is why its also … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)