Display url variable from views.py in Django template
<p>I want have my <em>url</em> come from <strong>views.py</strong> and then I can pass it as variable to <code>href</code> tag in template.</p>

<p><strong>views.py:</strong></p>

<pre><code>context {
    'urlLink': "{% url 'myapp:theURL' %}"
    ...
}
</code></pre>

<p><strong>index.html:</strong></p>

<pre><code>&lt;a href="{{ urlLink }}" LINK 1 &lt;/a&gt;
</code></pre>

<p>I have the above and it is not working. I have also tried <code>&lt;a href="{{ urlLink|escape }}" LINK 1 &lt;/a&gt;</code> but no success. </p>

<p>you need <a href="https://docs.djangoproject.com/en/1.10/ref/urlresolvers/#reverse" rel="nofollow">reverse</a></p>

<pre><code>context {
    'urlLink': "%s" % reverse('view_name')
}
</code></pre>

<p>you cannot use <code>{% url 'myapp:theURL' %}</code> in views.py since this is a template tag</p>

python django