Hi, folks
I’ve got a question that I can’t seem to resolve. I’ve got the following view →
def search(request):
search_string = request.GET.get('search-for').strip()
if Archiver.is_url(search_string):
return HttpResponseRedirect(reverse('searchnet:archive', args=(unquote(search_string),)))
# return HttpResponseRedirect(reverse('searchnet:archive', args=('search_string',)))
engine = SearchEngine()
search_results = engine.internal(search_string)
template = 'searchnet/results.html'
context = {
"menu": CATEGORIES,
"search_results": search_results[:10],
}
The bit I’m concerned with is this bit here →
if Archiver.is_url(search_string):
return HttpResponseRedirect(reverse('searchnet:archive', args=(unquote(search_string),)))
# return HttpResponseRedirect(reverse('searchnet:archive', args=('search_string',)))
I know the redirect is working because the commented out return line passes the string “search_string” to the template.
When I run it how it is, simply trying to pass the string of the url in exactly the same way I get the following error →
NoReverseMatch at /search/
Reverse for ‘archive’ with arguments '('https://docs.djangoproject.com/en/4.0/ref/validators/’,)’ not found. 1 pattern(s) tried: [‘archive/(?P<search_string>[^/]+)\Z’]
I really thought unquote() was the answer to my woes when I discovered it, but it’s not working even though the url is a string. I don’t get it and I’ve run out of ideas.
Can someone explain this, please, and possibly what I have to do to fix it. Thanks