url templatetag in django and direct_to_template

Go To StackoverFlow.com

0

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 ?

2012-04-04 22:36
by Stefano Borini


2

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.

2012-04-04 22:42
by James Aylett
ah right, the name. I forgot about that. Thank - Stefano Borini 2012-04-04 23:07
Ads