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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf-renderer-xlsx-0.2.4.tar.gz.
File metadata
- Download URL: drf-renderer-xlsx-0.2.4.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e44582478219f9b9041efe66b07c67ec7d4f1a7cbf48c7b2c265fedfd338051c
|
|
| MD5 |
db3a717bf9f9519fbb2b93d91bd13196
|
|
| BLAKE2b-256 |
c82992c89c324fc17ded8d0a557a4b67d4533dd17da05498e2f9b3cff29ff5c8
|
File details
Details for the file drf_renderer_xlsx-0.2.4-py3-none-any.whl.
File metadata
- Download URL: drf_renderer_xlsx-0.2.4-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
637d8d709c38697070ebebbc9f725b42a24b172768a81fa6a251dd43da03114f
|
|
| MD5 |
a66e294029e9fa2049379825482828e0
|
|
| BLAKE2b-256 |
af53f2d73e4bc1e35351f47b89129856a4431a2bf2519c1d95b0a7291f663146
|