I want to reference a dynamic url in my templates using its name, but am not sure how to incorporate the object id. In other words, I want to reference “/products/98” in my template without having to hard code it (as my url patterns might change).
In my urls.py, I have:
url(r'^products/(\d+)/$', 'products.views.show_product', name='product'),
How do I name my pattern such that I can call {% url ??? %} in the template to get the correct item with a specified id. e.g.
{% for product in product_list %}
<a href="{% url ??? %}">Product #{% product.id %}</a>
{% endfor %}
urls.py:
template:
Make sure your products.views.show_product view function takes product_id as a parameter.