JSONP support for Django REST Framework
Full documentation for the project is available at http://jpadilla.github.io/django-rest-framework-jsonp.
Overview
JSONP support extracted as a third party package directly from the official Django REST Framework implementation.
Warning: If you require cross-domain AJAX requests, you should almost certainly be using the more modern approach of CORS as an alternative to JSONP. See the CORS documentation for more details.
The jsonp approach is essentially a browser hack, and is only appropriate for globally readable API endpoints, where GET requests are unauthenticated and do not require any user permissions.
Requirements
Python (2.7, 3.3, 3.4)
Django (1.6, 1.7)
Django REST Framework (2.4.3, 2.4.4, 3.0-beta)
Installation
Install using pip…
$ pip install djangorestframework-jsonp
Example
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework_jsonp.renderers.JSONPRenderer',
),
}
You can also set the renderer used for an individual view, or viewset, using the APIView class based views.
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_jsonp.renderers import JSONPRenderer
class ExampleView(APIView):
"""
A view that returns the count of active users in JSONP
"""
renderer_classes = (JSONPRenderer,)
def post(self, request, format=None):
user_count = User.objects.filter(active=True).count()
content = {'user_count': user_count}
return Response(content)
Documentation & Support
Full documentation for the project is available at http://jpadilla.github.io/django-rest-framework-jsonp.
You may also want to follow the author on Twitter.
Metadata
Release files for djangorestframework-jsonp 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| djangorestframework-jsonp-1.0.0.tar.gz | 2.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| djangorestframework_jsonp-1.0.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 6.0 kB
Release files / djangorestframework-jsonp-1.0.0.tar.gz
| Download URL | djangorestframework-jsonp-1.0.0.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0117fa1f85829047fc9779215dc81777c1c3f2fa30d3316c111da4b7be213e99
|
|
BLAKE2b-256 checksum How to use checksums |
1dec052d439ec9a827218522478a9870017ec7b0b62a7fb1bf0f76f4fb95b53e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / djangorestframework_jsonp-1.0.0-py2.py3-none-any.whl
| Download URL | djangorestframework_jsonp-1.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 3.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
706f7d67f8d59f29bc448efeccb3d69f24c2d15d49ef08e56c013a784357118e
|
|
BLAKE2b-256 checksum How to use checksums |
287bfe7974eaeef20aa6b3913b9e546a979abd5292995031bcda3accdb187ee4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |