Django: accessing variable value from TemplateView
<p>Say I have the following url that maps to a <code>TemplateView</code>:</p>

<pre><code>url(r'^path/(?P&lt;var1&gt;\d+)/(?P&lt;var2&gt;\d+)/$', TemplateView.as_view('a_view.html'))
</code></pre>

<p>I thought in the template view <code>a_view.html</code> I could access the values of <code>var1</code> and <code>var2</code> as they're being captured and extracted into named parameters:</p>

<pre><code>&lt;!-- a_view.html --&gt;

&lt;p&gt;var1 value = {{ var1 }}&lt;/p&gt;
&lt;p&gt;var2 value = {{ var2 }}&lt;/p&gt;
</code></pre>

<p>However, these values are blank when visiting <code>/path/10/89</code>. Why? How can I access them then? Would I need an explicit view?</p>

<p>From template you can access the instance of <a href="https://docs.djangoproject.com/en/1.10/ref/urlresolvers/#django.urls.ResolverMatch" rel="nofollow">ResolverMatch</a> representing the resolved URL</p>

<pre><code>&lt;p&gt;var1 value = {{ request.resolver_match.kwargs.var1 }}&lt;/p&gt;
&lt;p&gt;var2 value = {{ request.resolver_match.kwargs.var2 }}&lt;/p&gt;
</code></pre>

python django