Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Python 100 Days | 135,076 | a month ago | 682 | Python | ||||||
Python - 100天从新手到大师 | ||||||||||
Django Rest Framework | 25,649 | 24,595 | 1,508 | 2 days ago | 134 | December 15, 2021 | 132 | other | Python | |
Web APIs for Django. 🎸 | ||||||||||
Awesome Django | 7,045 | 2 days ago | 2 | cc0-1.0 | HTML | |||||
A curated list of awesome things related to Django | ||||||||||
Drf Yasg | 3,092 | 290 | 76 | 16 days ago | 59 | October 25, 2020 | 235 | other | Python | |
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code. | ||||||||||
Django Rest Swagger | 2,516 | 2,031 | 41 | 3 years ago | 50 | April 30, 2018 | 168 | bsd-2-clause | Python | |
Swagger Documentation Generator for Django REST Framework: deprecated | ||||||||||
Django Rest Auth | 2,331 | 1,109 | 24 | 10 months ago | 25 | April 01, 2019 | 234 | mit | Python | |
This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON) | ||||||||||
Djoser | 2,288 | 212 | 5 | 7 days ago | 48 | October 30, 2020 | 166 | mit | Python | |
REST implementation of Django authentication system. | ||||||||||
Drf Nested Routers | 1,487 | 621 | 29 | 10 days ago | 19 | October 15, 2021 | 46 | apache-2.0 | Python | |
Nested Routers for Django Rest Framework | ||||||||||
Cookiecutter Django Rest | 1,405 | 6 hours ago | 4 | mit | Python | |||||
Build best practiced apis fast with Python3 | ||||||||||
Drf Extensions | 1,371 | 323 | 14 | 5 days ago | 16 | July 30, 2021 | 75 | mit | Python | |
DRF-extensions is a collection of custom extensions for Django REST Framework |
CSV Tools for Django REST Framework
Author: Mjumbe Wawatu Poe, Follow me on Twitter.
$ pip install djangorestframework-csv
views.py
from rest_framework.views import APIView
from rest_framework.settings import api_settings
from rest_framework_csv import renderers as r
class MyView (APIView):
renderer_classes = (r.CSVRenderer, ) + tuple(api_settings.DEFAULT_RENDERER_CLASSES)
...
Alternatively, to set CSV as a default rendered format, add the following to the settings.py file:
REST_FRAMEWORK = {
# specifying the renderers
'DEFAULT_RENDERER_CLASSES': (
'rest_framework_csv.renderers.CSVRenderer',
),
}
By default, a CSVRenderer
will output fields in sorted order. To specify
an alternative field ordering you can override the header
attribute. There
are two ways to do this:
Create a new renderer class and override the header
attribute directly:
class MyUserRenderer (CSVRenderer): header = ['first', 'last', 'email'] @api_view(['GET']) @renderer_classes((MyUserRenderer,)) def my_view(request): users = User.objects.filter(active=True) content = [{'first': user.first_name, 'last': user.last_name, 'email': user.email} for user in users] return Response(content)
Use the renderer_context
to override the field ordering on the fly:
class MyView (APIView): renderer_classes = [CSVRenderer] def get_renderer_context(self): context = super().get_renderer_context() context['header'] = ( self.request.GET['fields'].split(',') if 'fields' in self.request.GET else None) return context ...
Custom labels can be applied to the CSVRenderer
using the labels
dict
attribute where each key corresponds to the header and the value corresponds
to the custom label for that header.
1) Create a new renderer class and override the header
and labels
attribute directly:
class MyBazRenderer (CSVRenderer): header = ['foo.bar'] labels = { 'foo.bar': 'baz' }
Using the renderer with paginated data is also possible with the new PaginatedCSVRenderer class and should be used with views that paginate data
For more information about using renderers with Django REST Framework, see the API Guide or the Tutorial.
To run the tests against the current environment:
$ ./manage.py test
CSVRenderer
, thanks to @sobyCSVRenderer
headers, labels, and writer_opts as
renderer_context
parameters.CSVRenderer.headers
to CSVRenderer.header
; old spelling is
still available for backwards compatibility, but may be removed in the future.headers
attribute.