Pass data from a template tag to a django view
<p>I'd like to pass a parameter with data, like category_id=2 from my template to the view.  Here is how I think it should work (which obviously doesn't)...</p>

<p>The view </p>

<pre><code>def category_detail(request, category_id):
    return_list = Category.objects.filter(category_id=category_id)
    return render(request,
                  'expense_list.html',
        {
            'expense_list' : return_list
        })
</code></pre>

<p>HTML in the template:</p>

<pre><code>&lt;a href="{% url 'category_detail' category_id=2 %}"&gt;Blah&lt;/a&gt;
</code></pre>

<p>Urls file:</p>

<pre><code>url(r'^detail/(?P&lt;category_id&gt;[0-9]+)/$', views.category_detail, name='category_detail'),
</code></pre>

<p>You can build a list of urls by doing something like:</p>

<pre><code>{% for category in expense_list.all %}
    &lt;a href="{% url 'app_label:view_name' category_id=category.id %}"&gt;{{ category.name }}&lt;/a&gt;
{% endfor %}
</code></pre>

<p>Where app_label is the label/name of the app and view_name in this case category_detail.</p>

python django