A
A
Andrei1penguin12021-03-26 01:02:41
Django
Andrei1penguin1, 2021-03-26 01:02:41

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

1 answer(s)
A
Andrew, 2021-03-26
@Andrei1penguin1

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)}'

Adapt it yourself to FBV, it's easy there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question