Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to embed a tag within a url templatetag in a django template?
    primarykey
    data
    text
    <p>How do I embed a tag within a <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url" rel="nofollow noreferrer" title="url templatetag">url templatetag</a> in a django template?</p> <p>Django 1.0 , Python 2.5.2</p> <p>In views.py</p> <pre><code>def home_page_view(request): NUP={"HOMEPAGE": "named-url-pattern-string-for-my-home-page-view"} variables = RequestContext(request, {'NUP':NUP}) return render_to_response('home_page.html', variables) </code></pre> <p>In home_page.html, the following</p> <pre><code>NUP.HOMEPAGE = {{ NUP.HOMEPAGE }} </code></pre> <p>is displayed as </p> <pre><code>NUP.HOMEPAGE = named-url-pattern-string-for-my-home-page-view </code></pre> <p>and the following url named pattern works ( as expected ),</p> <pre><code>url template tag for NUP.HOMEPAGE = {% url named-url-pattern-string-for-my-home-page-view %} </code></pre> <p>and is displayed as </p> <pre><code>url template tag for NUP.HOMEPAGE = /myhomepage/ </code></pre> <p>but when <code>{{ NUP.HOMEPAGE }}</code> is embedded within a <code>{% url ... %}</code> as follows</p> <pre><code>url template tag for NUP.HOMEPAGE = {% url {{ NUP.HOMEPAGE }} %} </code></pre> <p>this results in a template syntax error</p> <pre><code>TemplateSyntaxError at /myhomepage/ Could not parse the remainder: '}}' from '}}' Request Method: GET Request URL: http://localhost:8000/myhomepage/ Exception Type: TemplateSyntaxError Exception Value: Could not parse the remainder: '}}' from '}}' Exception Location: C:\Python25\Lib\site-packages\django\template\__init__.py in __init__, line 529 Python Executable: C:\Python25\python.exe Python Version: 2.5.2 </code></pre> <p>I was expecting <code>{% url {{ NUP.HOMEPAGE }} %}</code> to resolve to <code>{% url named-url-pattern-string-for-my-home-page-view %}</code> at runtime and be displayed as <code>/myhomepage/</code>.</p> <p>Are embedded tags not supported in django? </p> <p>is it possible to write a custom url template tag with embedded tags support to make this work?</p> <p><code>{% url {{ NUP.HOMEPAGE }} %}</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload