I’ve got this Serializer translating path to url, and it works on its own, but when i try to nest this serializer inside another serializer, i get this error. Do you have any idea why? I need to have this function, because otherwise it just shows the paths to the image in this main SpecialistSerializer. Traceback: Answer In to_representation, you
Tag: django-rest-framework
add a single data to serializer in django
I’m writing an API where the user’s followers are listed.I also want to send the total number of followers in this API.But the totalFollower field keeps repeating.I only want it sent once. Like that: MY serializer Answer You have a couple of options: Use a DRF paginator on your view, which will give a count in the response body: Alternatively
Django CSRF verification failed. Webhook payment system
I’m trying to implement a webhook for my payment system. I have a path to my webhook view, which is a simple definition where the provided id is printed. The usage is like this Path View I’m getting the following error Answer Use the csrf_exempt decorator to mark the view as exempt from CSRF checks
DRF Serializer – Accept field but don’t use it in `create` or `update`
I have a model Message that has a FileField. My API accepts files in Base64 encoding so they can be sent alongside other data. To know a filename and an extension, there is one more field attachment_filename in the serializer that is not a model field. It is used inside Base64Field. I want to be able to validate if there
Django Rest Frame Work: passing User in djago rest frame work
I have a Django project as following code in model following code in serializer and following code in view when I send a post request by postman and send username and password in Authorization tab it error: but if I type username or password incorrect it will be can everybody help me? Answer Your serializer has no idea about the
How to get the param PK in django restframework permission?
I have this permission in Django that look like this: Can anybody help me get the params of request I tried using self.kwargs[“pk”], request.POST[‘pk’] but they all return saying object has no attribute. Answer If pk is a parameter of the POST request, you can access it with request.POST.get(‘pk’). In your post, you are not using get(), so that could
How to serialize first photo in album? Django
How to serialize first photo in album if photo connected by using FK with model Gallery. I need first photo for gallery cover in galley list. My models: Anyone have any ideas? May be I need suchlike request Gallery.objects.get(id=id).photos.first() but i not sure is it correct. Answer get returns only one object. filter returns multiple objects. You can access the
Getting CSRF token missing error on a django rest framework (with TokenAuthentication) public APIView
I’m having issue with Django Rest Framework and CSRF configurations. I know there are plenty of similar posts on the subject (like this one Django Rest Framework remove csrf) but most of them do not apply (I’m not using SessionAuthentication, nor Django templates), and the way DRF handles CSRF is still unclear to me. Here is the situation : I
how to pass input to api from angular forms without formControlName?
I am passing some data from angular to django rest api, Which is as follows first what django need in for api: what I am passing from angular now my issue is that I am not taking classname as input because It doesn’t make sense here so is there any other way by which I directly pass classname to api
Django Rest-Framework During Validation, Check the Request Method Type
I am working on API Validation Errors to be called. I have to make sure 2 dates don’t overlap when making new “POST” calls, which is working fine. I am doing a model.objects.Filter() query and if anything gets returned, I return a validation error. However, I want to return this error only during POST requests. I have tried if request.method