简体   繁体   中英

Django GET ?q=“parameter” in get_queryset Class Based View

How do I access the "parameter" word in the url:

operations_product_search/?q=parameter

here:

class ASearchView(ListView):

...

def get_queryset(self, **kwargs):
    q = self.kwargs["q"]  <--- This is not working

它应该是self.request.GET['q']

I get query parameters using query_params

def get_queryset(self):
    q = self.request.query_params.get('q', None)

If you use get() , you can avoid an exception if 'q=' is not present in the URL, by providing a fallback value ( None here):

 def get_queryset(self):
     q = self.request.GET.get('q', None)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM