Skip to main content

DIY Django's JsonResponse and JsonpResponse

Project description

django-json-response

Installation

pip install django-json-response

Warning

Since Version 1.1.3, the JsonpResponse return Object replace of String.

"{}('{}')" ==> '{}({});'

Usage

from json_response import JsonResponse

def json_view(request):
    objs = SomeModel.objects.all()

    return JsonResponse({
        'status': 200,
        'message': u'成功',
        'data': {
            'data1': 'xxx',
            'data2': 'ooo',
            'objs': [obj.data for obj in objs]
        }
    })


or


from json_response import JsonpResponse

def jsonp_view(request):
    callback = request.GET.get('callback', '')

    objs = SomeModel.objects.all()

    return JsonpResponse(callback, {
        'status': 200,
        'message': u'成功',
        'data': {
            'data1': 'xxx',
            'data2': 'ooo',
            'objs': [obj.data for obj in objs]
        }
    })

or

from json_response import json_response, jsonp_response, auto_response

@json_response
def json_view(request):
    objs = SomeModel.objects.all()

    return {
        'status': 200,
        'message': u'成功',
        'data': {
            'data1': 'xxx',
            'data2': 'ooo',
            'objs': [obj.data for obj in objs]
        }
    }

@jsonp_response
def jsonp_view(request):
    objs = SomeModel.objects.all()

    return {
        'status': 200,
        'message': u'成功',
        'data': {
            'data1': 'xxx',
            'data2': 'ooo',
            'objs': [obj.data for obj in objs]
        }
    }

@auto_response
def jsonp_view(request):
    objs = SomeModel.objects.all()

    return {
        'status': 200,
        'message': u'成功',
        'data': {
            'data1': 'xxx',
            'data2': 'ooo',
            'objs': [obj.data for obj in objs]
        }
    }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-json-response-1.1.3.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

django_json_response-1.1.3-py2-none-any.whl (4.2 kB view details)

Uploaded Python 2

File details

Details for the file django-json-response-1.1.3.tar.gz.

File metadata

File hashes

Hashes for django-json-response-1.1.3.tar.gz
Algorithm Hash digest
SHA256 b4cc043dcacc7eb48d4f64b3200f440435c8be9089af119fd5d4f25612dfc7f7
MD5 1e96c653f21ec5cfffa4c88055cca26d
BLAKE2b-256 309e071310badfb4a27f7b4a8480f2e2631a0d49fe3e93f2836509414d377cc1

See more details on using hashes here.

File details

Details for the file django_json_response-1.1.3-py2-none-any.whl.

File metadata

File hashes

Hashes for django_json_response-1.1.3-py2-none-any.whl
Algorithm Hash digest
SHA256 7f0d162e1e900a5c70f24d087af4faf54c7aad07df1d346e2569bf02181a2ed1
MD5 d3994a76c44d02103038b3801a6f84b4
BLAKE2b-256 853c04e4f70ca05dacd7d7e46fae0cfd6cd3dfa057aa468d4d97402102d72dbe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page