+1 vote
ago by
Good afternoon, there is a task to redirect from one page to another, passing arguments, something like
return redirect("url", arg=True)
But it throws an error:
NoReverseMatch at /url/
Reverse for 'page' with keyword arguments '{'arg': True}' not found. 1 pattern(s) tried: ['$'] What am I doing wrong?

1 Answer

0 votes
ago by
 
Best answer
The arguments are explained in the documentation, but if you mean the query string, then:

CBV:
from django.views.generic import RedirectView
from django.urls import reverse
from django.utils.http import urlencode


class SomeRedirectView(RedirectView):

def get_redirect_url(self, **kwargs):
query_dict = {'allowed': True}
return f'{reverse("index")}?{urlencode(query_dict)}'
Adapt for FBV yourself, it's not hard
...