Using URL Names in Views

Is it possible to use URL names in views, for example, can we do this in a template?

+6
django django-views
source share
2 answers
+1
source share

Check documents for reverse

They have a concrete example modifying a named URL:

https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls

reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None)

viewname is either a function name (either a function reference, or a string version of the name if you used this form in urlpatterns) or the URL pattern name.

 def myview(request): return HttpResponseRedirect(reverse('arch-summary', args=[1945])) 
+6
source share

All Articles