Metadata-Version: 2.0
Name: django-json-response
Version: 1.1.3
Summary: DIY Django's JsonResponse and JsonpResponse
Home-page: https://github.com/Brightcells/django-json-response
Author: Hackathon
Author-email: kimi.huang@brightcells.com
License: UNKNOWN
Keywords: django-json-response django-jsonp-response
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Office/Business :: Financial :: Spreadsheet

====================
django-json-response
====================

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


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]
            }
        }




