django ListView的使用 ListView中获取url中的参数值

view.py

from django.views.generic import ListView,DetailView
from xxxx.models import Model_Name
class Colortag_view(ListView):
    #context_object_name = '如果不指定的话在html页面中 可以使用object_list获取'  
    context_object_name = 'object_list'
    #template_name='html页面所在目录'
    template_name='caradmin/colortags/colortags.html'
    #自定义查询方法
    def get_queryset(self):
        #获取url 中的值 比如http://127.0.0.1/admin/colortags/?name_text=红色
        print(self.request.GET.dict())
        return Model_Name.objects.filter(**self.request.GET.dict())

urls.py

from . import views
urlpatterns = [
    path('colortags/', views.Colortag_view.as_view(), name = 'modelname_list'),
]

猜你喜欢

转载自blog.csdn.net/weixin_38570967/article/details/81414128