1đź‘Ť
âś…
This code won’t work because:
-
JavaScript code is run by the client, long after the template tags ({% if data2 == “general” %} etc. ) are compiled in the server.
-
You can’t send data from JS to django like that for data2. (Although you could use AJAX), but that is not required in this case.
Why don’t you could do something like this, instead of relying on Javascript?
<p class= "rep3" width="100" id="val1" data1={{ family }} style= "display:none;">{{ family }}</p>
<p class= "rep4" width="100" id="val2" data2="" style= "display:none;"></p>
{% if family == "general" %}
<a href="/one_category/all/">criteria1</a>
{% else %}
{% if family == "ceramic" %}
<a href="/one_category/ceramic/">criteria2</a>
{% else %}
<a href="/image3/">criteria</a>
{% endif %}
{% endif %}
👤Amit
Source:stackexchange.com