A simple PDF renderer for Django Rest Framework
Project description
# DRF-PDF
[![Build Status](https://travis-ci.org/drgarcia1986/drf-pdf.svg?branch=master)](https://travis-ci.org/drgarcia1986/drf-pdf)
[![Coverage Status](https://coveralls.io/repos/drgarcia1986/drf-pdf/badge.svg)](https://coveralls.io/r/drgarcia1986/drf-pdf)
A simple PDF utils for Django Rest Framework
## Example
```python
# coding: utf - 8
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from drf_pdf.renderer import PDFRenderer
from my_pdf_package import PDFGenerator
class PDFHandler(APIView):
renderer_classes = (PDFRenderer, )
def get(self, request):
pdf = PDFGenerator('foo')
headers = {
'Content-Disposition': 'filename="foo.pdf"',
'Content-Length': len(pdf),
}
return Response(
pdf,
headers=headers,
status=status.HTTP_200_OK
)
```
### With two or more renderer_classes
```python
# coding: utf - 8
from rest_framework import status
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer
from rest_framework.views import APIView
from drf_pdf.response import PDFResponse
from drf_pdf.renderer import PDFRenderer
from my_pdf_package import get_pdf
class PDFHandler(APIView):
renderer_classes = (PDFRenderer, JSONRenderer)
def get(self, request, pdf_id):
pdf = get_pdf(pdf_id)
if not pdf:
return Response(
{'error': 'Not found'},
status=status.HTTP_404_NOT_FOUND
)
return PDFResponse(
pdf=pdf,
file_name=pdf_id
status=status.HTTP_200_OK
)
```
[![Build Status](https://travis-ci.org/drgarcia1986/drf-pdf.svg?branch=master)](https://travis-ci.org/drgarcia1986/drf-pdf)
[![Coverage Status](https://coveralls.io/repos/drgarcia1986/drf-pdf/badge.svg)](https://coveralls.io/r/drgarcia1986/drf-pdf)
A simple PDF utils for Django Rest Framework
## Example
```python
# coding: utf - 8
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from drf_pdf.renderer import PDFRenderer
from my_pdf_package import PDFGenerator
class PDFHandler(APIView):
renderer_classes = (PDFRenderer, )
def get(self, request):
pdf = PDFGenerator('foo')
headers = {
'Content-Disposition': 'filename="foo.pdf"',
'Content-Length': len(pdf),
}
return Response(
pdf,
headers=headers,
status=status.HTTP_200_OK
)
```
### With two or more renderer_classes
```python
# coding: utf - 8
from rest_framework import status
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer
from rest_framework.views import APIView
from drf_pdf.response import PDFResponse
from drf_pdf.renderer import PDFRenderer
from my_pdf_package import get_pdf
class PDFHandler(APIView):
renderer_classes = (PDFRenderer, JSONRenderer)
def get(self, request, pdf_id):
pdf = get_pdf(pdf_id)
if not pdf:
return Response(
{'error': 'Not found'},
status=status.HTTP_404_NOT_FOUND
)
return PDFResponse(
pdf=pdf,
file_name=pdf_id
status=status.HTTP_200_OK
)
```
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
drf-pdf-0.1.0.zip
(7.3 kB
view details)
File details
Details for the file drf-pdf-0.1.0.zip
.
File metadata
- Download URL: drf-pdf-0.1.0.zip
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33dc865a0b6cdf5093546f8611b49c3fee72f1f3f80089b9f3fa0969fa177395 |
|
MD5 | 4f934062098b9749ca8be757f6e06cb3 |
|
BLAKE2b-256 | d08636322f30a97ac8ccfbe9a27adf9b1d09784328365c7e601a3454793cf10e |