本文介绍了Jquery代码为Django REST框架分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{计数:18,下一个:http://127.0.0.1:8000/ajax/list/?page=6&format=json,
previous:http://127.0.0.1 :8000 / ajax / list /?page = 4& format = json,
results:[{subject:fd,date:2014-06-20,time_start :3:36 AM},
{subject:fdf,date:2014-06-14,time_start:3:38 AM}]}
http url
http://127.0.0.1:8000/ajax/list/?page=5&format=json
django urls.py
url(r'^ ajax / list / $',AuthorListAll1.as_view(),name ='ajax_list'),
http url
http://127.0.0.1:8000/ajax/list/
我得到这个
$ django视图中的b $ b
是template_n ame ='authorListAjax.html'工作?为什么要获得这个
$ $ $ $ $ $ $ $ $ $ $ $ $ $,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 'time_start')
class AuthorListAll1(ListAPIView):
template_name ='authorListAjax.html'
queryset = Author.objects.all()
serializer_class = AccountSerializer
paginate_by = 2
paginate_by_param ='page_size'
max_paginate_by = 100
解决方案
您需要定义适当的渲染器类,您可以将其放在设置中:
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES':(
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.TemplateHTMLRenderer',
'rest_framework.renderers.Bro wsableAPIRenderer',
)
}
或在您的视图类中,通过添加属性:
renderer_classes =(JSONRenderer,TemplateHTMLRenderer,BrowsableAPIRenderer)
I have this json with pagination from Django REST framework but I don't know how to use it.
{"count": 18, "next": "http://127.0.0.1:8000/ajax/list/?page=6&format=json",
"previous": "http://127.0.0.1:8000/ajax/list/?page=4&format=json",
"results": [{"subject": "fd", "date": "2014-06-20", "time_start": "3:36 AM"},
{"subject": "fdf", "date": "2014-06-14", "time_start": "3:38 AM"}]}
http url
http://127.0.0.1:8000/ajax/list/?page=5&format=json
django urls.py
url(r'^ajax/list/$', AuthorListAll1.as_view(), name='ajax_list'),
http url
http://127.0.0.1:8000/ajax/list/
I get this http://imgur.com/fMlyXDN
in django view, is template_name = 'authorListAjax.html' work? why do I get this http://imgur.com/fMlyXDN
class AccountSerializer(serializers.ModelSerializer):
class Meta:
model = Author
fields = ('subject', 'date', 'time_start')
class AuthorListAll1(ListAPIView):
template_name = 'authorListAjax.html'
queryset = Author.objects.all()
serializer_class = AccountSerializer
paginate_by = 2
paginate_by_param = 'page_size'
max_paginate_by = 100
解决方案
You need to define proper renderer classes, you can do it by putting this in your settings:
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.TemplateHTMLRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
)
}
or in your view class, by adding the property:
renderer_classes = (JSONRenderer, TemplateHTMLRenderer, BrowsableAPIRenderer)
这篇关于Jquery代码为Django REST框架分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!