简体   繁体   中英

django - view for redirecting to another page with query recieved

I have two search inputs, first on home page another on search results itself. what im try to do is receive query form home and redirect it to search results page according to this : Like I search - html-5 redirect page should be - 127.0.0.1/html-5/find/?q=html-5 I have tried but unfortunately not getting the right way to it, please suggest me the correct way to do it. I use these url patterns

url(r'^(?P<key>.*)/find/', FacetedSearchView.as_view(), name='haystack_search'),
url(r'^search/',category_query_view,name='category_query'),

then in category_query

def category_query_view(request):
category = request.GET.get('q')
print('hihi',category)
return HttpResponseRedirect(reverse('haystack_search', kwargs={'key':category},))

It is redirecting me to

127.0.0.1/html-5/find/

but i don't know how to add

/?q=html-5

in after this?

Oh, I get the right way, its pretty simple

def category_query_view(request):
category = request.GET.get('q')
print('hihi',category)
url = '{category}/find/?q={category}'.format(category=category)
return HttpResponseRedirect('/'+url)

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