Django REST Framework renderer for spreadsheet (xlsx) files.
Project description
Django REST Framework Renderer: XLSX
drf-renderer-xlsx
provides an XLSX renderer for Django REST Framework. It uses OpenPyXL to create the spreadsheet and returns the data.
Requirements
It may work with earlier versions, but has been tested with the following:
- Django >= 1.11
- Django REST Framework >= 3.6
- OpenPyXL >= 2.4
Installation
pip install drf-renderer-xlsx
Then add the following to your REST_FRAMEWORK
settings:
REST_FRAMEWORK = {
...
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
'drf_renderer_xlsx.renderers.XLSXRenderer',
),
}
To avoid having a file streamed without a filename (which the browser will often default to the filename "download", with no extension), we need to use a mixin to override the Content-Disposition like so:
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 MyExampleViewSet(XLSXFileMixin, ReadOnlyModelViewSet):
queryset = MyExampleModel.objects.all()
serializer_class = MyExampleSerializer
renderer_classes = (XLSXRenderer,)
Maintainer
Contributors (Thank You!)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for drf_renderer_xlsx-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 637d8d709c38697070ebebbc9f725b42a24b172768a81fa6a251dd43da03114f |
|
MD5 | a66e294029e9fa2049379825482828e0 |
|
BLAKE2b-256 | af53f2d73e4bc1e35351f47b89129856a4431a2bf2519c1d95b0a7291f663146 |