I want to create a list of entries in which each entry is linked to its page like this: wiki/entry-title. I’m using a for loop to add <li>s to HTML. here’s the code:
<ul>
{% for entry in entries %}
<li><a href="">{{ entry }}</a></li>
{% endfor %}
</ul>
urlpattern:
path('wiki/<str:title>', views.entry, name='entry')
what should I type in href to link the <li> to wiki/entry?
>Solution :
You can set your value in url as
<ul>
{% for entry in entries %}
<a href="/wiki/{{entry.value}}"><li>{{ entry }}</li></a>
{% endfor %}
</ul>
Its better to use {% url %} [Django-doc] template tags as
<ul>
{% for entry in entries %}
<a href="{% url 'your-url-name' entry.value %}"><li>{{ entry }}</li></a>
{% endfor %}
</ul>
NOTE : change value with your value accordingly. For e.g. {{entry.value}} or {{entry.title}} or {{entry.id}}