I am doing a search on the page with the ability to filter. It is necessary to pass the selected fields to form the correct queryset
. What is the best way to do this? I am creating str variable in urls
. But what if you need to pass 10 or more filter conditions? how to organize dynamically passed variables?
urls
from django.urls import path
from .views import *
urlpatterns = [
path('', OrdersHomeView.as_view(), name='orders_home'),
path('filter/<str:tag>', OrdersFilterView.as_view(), name='orders_filter'),
]
I understand what to do through ?var=&var2=
, as in php, but I can't figure out how? it is possible to just process the string str
, but maybe there is some django magic?
Make the filter view to work with URL GET params:
page = request.GET.get('page', 0)
page_size = request.GET.get('page_size', 100)
Then construct your URLs to send the filters filter/tag/?page=1&page_size=20
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.