DIY Django's JsonResponse and JsonpResponse
Project description
====================
django-json-response
====================
django-json-response
====================
class JsonResponse(data, encoder=DjangoJSONEncoder, safe=True, **kwargs) 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
Usage
=====
* JsonResponse::
from json_response import JsonResponse
def excelview(request):
objs = SomeModel.objects.all()
return JsonResponse({
'status': 200,
'message': u'成功'
'data': {
'data1': 'xxx',
'data2': 'ooo',
'objs': [obj.data for obj in objs]
}
})
* JsonpResponse::
from json_response import JsonpResponse
def excelview(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]
}
})
django-json-response
====================
django-json-response
====================
class JsonResponse(data, encoder=DjangoJSONEncoder, safe=True, **kwargs) 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
Usage
=====
* JsonResponse::
from json_response import JsonResponse
def excelview(request):
objs = SomeModel.objects.all()
return JsonResponse({
'status': 200,
'message': u'成功'
'data': {
'data1': 'xxx',
'data2': 'ooo',
'objs': [obj.data for obj in objs]
}
})
* JsonpResponse::
from json_response import JsonpResponse
def excelview(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]
}
})
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.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27fc8dab35b5e0fd1cea38538788dd068b05a4e53bf9503f79d65ff49b2b63e3 |
|
MD5 | 9d639c7dabafab37171e6c013eb3ebe0 |
|
BLAKE2b-256 | 124d34bb0d575c753d07438373ceb0295a6b311728da86776d4ceae901632b43 |
Close
Hashes for django_json_response-1.0.4-py2.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4474a3290b3cc0d1bb86afd2d7c7362a38a2f125440ddaedec7d9960051abd3b |
|
MD5 | e833186d3290b4eafab546d55232147f |
|
BLAKE2b-256 | 5554ef203b27aaba5d353b70b5acb139ef7c18f2f6c28f8dae779bcf41ce690b |