Questions tagged [django-drf-renderer]

21 questions
4
votes
0 answers

Django REST Framework change rederer class based on response

I'm using Django 2.2 and Django REST Framework. I have an APIView which will download Zip file on success response. class MultiDownloadCode(APIView): serializer_class = MultiDownloadSerializer permission_classes = ( …
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
4
votes
1 answer

renderer returned unicode, and did not specify a charset value

I am using Django 2.x and DRF. From my APIView, I want to return pdf or eps binary data file. class DownloadFile(APIView): serializer_class = DownloadFileSerializer renderer_classes = (BinaryFileRenderer,) def post(self, request): …
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
3
votes
1 answer

drf-yasg Customize SwaggerUIRenderer

I'd like to customize the style (font, colors, logo, etc) of drf_yasg generated docs. I see that I can extend drf_yasg/swagger-ui.html with the blocks extra_head, extra_styles, extra_body, extra_scripts, and can even overwrite the other blocks if I…
Vishal
  • 2,097
  • 6
  • 27
  • 45
3
votes
0 answers

Insert a custom row using drf-renderer-xlsx

I'm using drf-renderer-xlsx according of the official doc. The endpoint is ok and I can to export my data in xlsx format. My problem is that I need to insert a custom row to my file. Someone has any idea?
Joey Fran
  • 598
  • 2
  • 24
2
votes
2 answers

DRF normalize nested serializer to download excel report using XLSXRenderer

I have a ManyToMany field in my models. In serializer, I am able to get the nested serialized data, but I want to normalize it. models.py class Authors(models.Model): name = models.CharField(max_length=20) class Mets: db_table =…
2
votes
0 answers

GDALException OGR failure

I am working with Django DRF and GeoDjango for a simple model which is as follows. class Company(models.Model): name = models.CharField(max_length=200, default='Company', null=True) def __unicode__(self): return self.name class…
2
votes
2 answers

Django Rest Framework: Return response from mixin's dispatch method

In order to interact with slack, a server needs to be able to validate requests based on some cryptographic hashing. If this check returns false, the server should respond with a 400. It seems sensible to do this as a mixin: class…
2
votes
1 answer

DRF formatting XLSX content

I am trying to set a different color on every second row in XLSX file. From the documentation I see that I can pass some conditions using body property or get_body() method, but this only allows me to set somewhat "static" conditions. Here is the…
gonczor
  • 3,994
  • 1
  • 21
  • 46
2
votes
0 answers

how get the content of BrowsableAPIView in django channels (or ajax)

I use Django Channels to retrieve the data from Django Restful (DRF) serializer (I use channels because database is large and if I call for the data directly it results in a server timeout). What I struggle with (perhaps I don't understand…
1
vote
2 answers

Django Rest Framework - How to implement a view to return a javascript file?

I need to serve/return javascript files from a Django Rest Framework api, so in any other website client I can do: and import the content from it to my clients…
1
vote
1 answer

How to store http error response in Django

I'm getting name and age and storing in the database through DRF and creating middleware that checks errors and response errors and status_code and when the middleware errors occur like 404 "Page not found, invalid URL" etc. I want to store that…
1
vote
1 answer

Django Rest Framework: XLSXRenderer -- How to check condition for queryset and return a Response

from rest_framework.viewsets import ReadOnlyModelViewSet from drf_renderer_xlsx.mixins import XLSXFileMixin from drf_renderer_xlsx.renderers import XLSXRenderer from .models import MyExampleModel from .serializers import MyExampleSerializer class…
1
vote
1 answer

Django rest framework XLSX renderer + Apiview

I'm setting up an endpoint on my API which should return a XLSX-file. The DRF-docs mention https://github.com/wharton/drf-renderer-xlsx as the main external rendering package, aside from the pandas which also seem to be able to render XLSX. In their…
Thorvald
  • 546
  • 6
  • 18
1
vote
2 answers

How to get each column as one list from a Django QuerySet over DRF

Using Django-REST-framework, I have the following view: class MyRESTfulAPIView(APIView): permission_classes = [IsAuthenticated, MyCustomPermision] def get(self, request): data = MyModel.objects.values('field1').annotate(field2=...,…
1
vote
1 answer

Django Rest Framework using Viewsets with different renderers

does it make sense to use Django Rest Framework also to render my HTML Code with Bootstrap and so on...? If no, what is the best solution to split the API endpoints and HTML view? I exposed an API with DRF Viewsets and JSON serializers. It's…
1
2