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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f00a65c4981be3a1194668b69abc622a62dfc274f3db9f309c3f63d61cc7694f |
|
MD5 | 0265a816e31936bd603e3d85dcb02622 |
|
BLAKE2b-256 | 8a43809d6bf3cd5198f200b95206e00e226a1864dc32d64d0229396082ae4bc5 |
Close
Hashes for django_json_response-1.1.5-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb84d90d9a06585abc73ec73c077ee0a1f6c2938334309931dd5a65b0fc47383 |
|
MD5 | dcfec334694064e79aed6ce07c1a3aa9 |
|
BLAKE2b-256 | 629fc2a6c2ba7f42ec1255248cb05f6aa4ac53f51ed9835f5ab35f538b8f6f46 |