DIY Django's JsonResponse and JsonpResponse
Project description
django-json-response
JsonResponse is New in Django 1.7
Ref: https://docs.djangoproject.com/en/1.8/ref/request-response/#jsonresponse-objects
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-json-response-1.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bcaeb79741914ad9dc293466382cd161387551b80d19b75eac6bccfc2bb1d01 |
|
MD5 | 4d1e99e7752e94e6dc4554b15f0bf77a |
|
BLAKE2b-256 | 6a87b5f29addfa7dc997a2dda7ce70c0bbe96da21527aacc3308b07a2c2f8d99 |
Close
Hashes for django_json_response-1.1.4-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b91d625e425b59dc6e6cbd0d5bef064debd04284766f0a7c0454e7f6f96f041 |
|
MD5 | 42924dd291f86e0b2bd04ab91121df2f |
|
BLAKE2b-256 | bb6d108dd46244ef1fa766b33a7b8cd4e12530e5d53c782d36c9be3033c5f833 |