Stefano Borini
Stefano Borini

Reputation: 143795

url templatetag in django and direct_to_template

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 ?

Upvotes: 0

Views: 1220

Answers (1)

James Aylett
James Aylett

Reputation: 3372

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.

Upvotes: 2

Related Questions