Giter VIP home page Giter VIP logo

django-rest-framework-jsonp's Introduction

REST Framework JSONP

build-status-image pypi-version

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.

django-rest-framework-jsonp's People

Contributors

jpadilla avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.