This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Wrap view functions, allowng them render python native and custom objects to json

Usage

Simple wrap returning data into json

from jsonresponse import to_json

@to_json('plain')
def hello(request):
   return dict(hello='world')
GET /hello/
{"hello": "world"}

Result can be wraped in some api manier. Note, you can pass debug=1 to pretty print response. Use JSONRESPONSE_DEFAULT_DEBUG=True to enable by default.

@to_json('api')
def goodbye(request):
   return dict(good='bye')
GET /goodbye/?debug=1
{
    "data": {
        "good": "bye"
    },
    "err": 0
}

Automaticaly error handling, note response code is 500 here

@to_json('api')
def error(request):
   raise Exception('Wooot!??')
GET /error/
{
    "err_class": "Exception",
    "err_desc": "Wooot!??",
    "data": null,
    "err": 1
}

You can pass raise=1 to raise exceptions in debug purposes instead of passing info to json response

GET /error/?raise=1
Traceback (most recent call last):
Exception: Wooot!??

You can pass custom kwargs to json.dumps, just give them to constructor:

@to_json('plain', separators=(',', ':'))
def custom_kwargs(request):
   return ['a', { 'b': 1 }]
GET /
["a",{"b":1}]

You can serialize not only pure python data types. Implement serialize method on toplevel object or each element of toplevel array. Note, that request object is passed to serialize method.

class User(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def serialize(self, request):
        if request.GET.get('with_age', False):
            return dict(name=self.name, age=self.age)
        else:
            return dict(name=self.name)

@to_json('objects')
def users(request):
   return [User('Bob', 10), User('Anna', 12)]
GET /users/?with_age=1
{
    "data": [
        {
            "age": 10,
            "name": "Bob"
        },
        {
            "age": 12,
            "name": "Anna"
        }
    ],
    "err": 0
}

It is easy to use jsonp, just pass format=jsonp

GET /users/?format=jsonp
callback({
    "data": [
        {
            "name": "Bob"
        },
        {
            "name": "Anna"
        }
    ],
    "err": 0
});

You can override the name of callback method using JSONRESPONSE_CALLBACK_NAME option or query arg callback=another_callback

GET /users/?format=jsonp&callback=my_callback
my_callback({
    "data": [
        {
            "name": "Bob"
        },
        {
            "name": "Anna"
        }
    ],
    "err": 0
});
Release History

Release History

0.10.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.9.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-jsonresponse-0.10.0.tar.gz (4.8 kB) Copy SHA256 Checksum SHA256 Source Feb 10, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting