django-easy-response

Return HTTP responses in a easier way


License
MIT
Install
pip install django-easy-response==1.0.2

Documentation

django-easy-response

Return HTTP responses in a easier way

previously known as django-simple-response

Install

pip install django_easy_response

Basic Usage

settings.py

MIDDLEWARE_CLASSES = (
    ...
    # last on the list
    easy_response.middleware.EasyResponseMiddleware,
)

Want more settings? go here.

views.py

def view(request):
    # return HTTP response with status code 200 (default)
    return

def another_view(request):
    # return HTTP response with content and status code 401 
    return 401, 'Not authorized'

def yet_another_view(request):
    # return JSON/JSONP response with content and default status code
    return {'foo': 'bar'}

In a nutshell, you can either return:

  • an object, which will be serialized into the response's content.
  • a tuple, which first element defines the status code and the second the content of the response.

Want to know more? go here.