Answer the question
In order to leave comments, you need to log in
How to pass arguments to redirect django?
Good day, there is a task to redirect from one page to another, passing arguments along the way, something like
But this 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?
return redirect("url", arg=True)
Answer the question
In order to leave comments, you need to log in
About the arguments chewed in the documentation, if we are talking about 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)}'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question