my urls.py
url(r'^ACB/(?P<slug>.*)/$', views.ACB.as_view(), name='ACB'),
I have requirement where I need to send this url for couple of random slug as part of a response for an API
I do not want the url of request but url of different view
my urls.py
url(r'^ACB/(?P<slug>.*)/$', views.ACB.as_view(), name='ACB'),
I have requirement where I need to send this url for couple of random slug as part of a response for an API
I do not want the url of request but url of different view
Use reverse
from django.core.urlresolvers import reverse
my_url = reverse('ACB')
This would reverse the ACB
url without any argument. If slug is present, you can pass it in args
:
my_url = reverse('ACB', args=(slug,))
https://docs.djangoproject.com/en/1.9/ref/urlresolvers/#reverse
Update 2021 (Django 2.0+)
In Django 2.0, the module django.core.urlresolvers
was moved to django.urls
.
New solution to question:
from django.urls import reverse
my_url = reverse('ACB')
my_url = reverse('ACB', args=(slug,))
For further information, see: