I’ve read the docs like 5 times, I can’t see whats missing here.
I have a situation where reverse() works fine, but the same params passed to redirect() fails with an error stating the address cannot be resolved.
reverse("app:submission_thanks", kwargs={ "data": survey.data.slug, "survey": survey.slug })
redirect("app:submission_thanks", kwargs={ "data": survey.data.slug, "survey": survey.slug })
My url is:
url(r'^(?P<data>[-\w]+)/(?P<survey>[-\w]+)/thanks/$',
TemplateView.as_view(template_name="pasteur/submission_thanks.html"),
name="submission_thanks",
),
Redirect has a different method signature:
See shortcut redirect examples in the Django docs.
Diving into the code a little:
redirect(to, *args, **kwargs)callsresolve_url(to, *args, **kwargs)which callsurlresolvers.reverse(to, args=args, kwargs=kwargs). So this is definitely correct.You do not need to wrap the
argsin a list orkwargsin a dictionary when using theresolve_urlorredirectshortcut.