python - django-pagination分页url显示方式的问题
巴扎黑
巴扎黑 2017-04-17 14:35:43
0
2
825

django-pagination分页url默认显示方式,例如?page=2 可以改成/page/2的形式么?

巴扎黑
巴扎黑

reply all(2)
黄舟

The scenarios for these two usages are different

?page=2
The page=2 here is passed as url parameters. You can get it in request.kwargs in Django view. It is generally used to pass ordinary parameters:
request.kwargs['page'] # 2

/page/2/
This "2" is the ontology of the url. This usage is generally used with Django class-based view to automatically parse the Django model object corresponding to this "2"
For example url.py:

url(r'^user/(?P<pk>\d+)/edit/$', views.YourView.as_view(), name='your_view')

views.py:

from django.views.generic import DetailView
class YourView(DetailView):
    def get_object(self, queryset=None):
        pk = self.kwargs.get(self.pk_url_kwarg, None)
        if int(pk) == 0:
            return None
        return super(Yourview, self).get_object(queryset)

The get_object method here does something similar, so that you can access the object directly through self.object
You can refer to the official documentation
https://docs.djangoproject.com/en/1.7/topics/class-based-views/generic-display/

小葫芦

It feels like it has nothing to do with the paging class. It’s just a question of how to pass the page parameter. It can be passed through URLConf or created through QueryString. After getting this parameter, use pagination to implement paging

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!