Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using urls names in views

Is it possible to use urls names in views, like we can do it in template?

like image 554
szaman Avatar asked Jan 13 '11 08:01

szaman


1 Answers

Check out the docs on reverse

They have a specific example reversing a named url here:

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 the function name (either a function reference, or the string version of the name, if you used that form in urlpatterns) or the URL pattern name.

def myview(request):
    return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
like image 105
Yuji 'Tomita' Tomita Avatar answered Oct 21 '22 07:10

Yuji 'Tomita' Tomita