Django - only call <a href="{% url 'view'%}"> when clicked
In my web page i have a for loop that displays multiple <a>
tags. When one of the <a>
tags is clicked the user will be redirected to another url.
My problem is that all of the href="{% url 'search' theme_path %}{{theme}}"
gets called despite not being clicked and causes my page site to crash since the sub_themes
list is quite large.
I tried using forms as they should only call the {% url 'view' %}
when clicked. But this got a bit fiddly. There must be some simple javascript code that can resolve my issue
How can i only have the url
be called when clicked?
html
<section id="all-themes-container">
{% for theme in sub_themes %}
<div class="theme-container">
<a href="{% url 'search' theme_path %}{{theme}}">{{theme}}</a>
</div>
{% endfor %}
</section>