对django的简单jsonp支持
django_jsonp的Python项目详细描述
对django的简单jsonp支持
安装
使用pip…
安装$ pip install django-jsonp
用法
fromdjsonpimportjsonp,JSONPResponse,get_callback# decorate something that returns a dict-like object@jsonpdefmy_view(request):return{'foo':'bar'}# it can work with an HttpResponse instances@jsonpdefanother_view(request):returnHttpResponse("{'foo': 'bar'}")# or just return a JSONPResponsedefjsonp_view(request):returnJSONPResponse(data={'foo':'bar',},callback=get_callback(request))# it also works for CBVsfromdjango.views.genericimportView@jsonpclassDictResponse(View):defget(self,request):returnHttpResponse("{'foo': 'bar'}")