Reputation: 13376
I have the following urls configuration in my Django project:
urlpatterns = patterns('',
(r'^my-view$', MyViewClass.as_view()),
)
Is there a way to use the reverse()
function to get the url of the above view?
Upvotes: 5
Views: 4353
Reputation: 1
If that url
requires an argument like:
url('<<int:input>>', ClassView.as_view(), name='link')
Upvotes: -2
Reputation: 13376
Yes there is.
Use the name
argument of the url
function to define a name for the url, then you can use reverse
on this name:
from django.conf.urls import patterns, url
urlpatterns = patterns('',
url(r'^my-view$', MyViewClass.as_view(), name='my_view'),
)
reverse('my_view')
Upvotes: 10