I have 2 views: a and b they all render to one template T. There are also a_2 and b_2 views. And T template should generate urls to the a_2 and b_2 views.
however I cannot use {% url %} because I cannot pass url name as a parametr.
I cannot generate the whole url in views because i should do it multiple times (one on a row in a table - so it could be hundreeds of links)
I do not want to write 2 exactly the same template. So the question is - how to avoid this ?
This is fixed in django 1.5.
In versions prior to 1.5 you need to use
{% extends 'base.html' %}
{% load url from future %}
{% url 'name_as_a_string' %}
{% url name_stored_in_variable %}
From https://docs.djangoproject.com/en/dev/releases/1.5/
One deprecated feature worth noting is the shift to “new-style” url tag. Prior to Django 1.3, syntax like {% url myview %} was interpreted incorrectly (Django considered "myview" to be a literal name of a view, not a template variable named myview). Django 1.3 and above introduced the {% load url from future %} syntax to bring in the corrected behavior where myview was seen as a variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With