I want to use the url
templatetag in django, but the url I want to resolve is associated to something that is rendered through direct_to_template, so I don't have a view function to pass to url
. Is it possible to use it in any case, or should I create a trivial view ?
If you name the URL in your urlconf, you can use that with the url
templatetag. In your urlconf:
urlpatterns += patterns('',
url(
r'^whatever/your/url/pattern/is/$',
direct_to_template,
{ 'template': 'wherever/your/template/is.html' },
name='name-of-url'
),
)
In your template:
{% url name-of-url %}
This is covered in Naming URL patterns in the Django documentation.