I'm trying to link two webpages in django framework, using anchor tags in template. One of my view takes an argument and I can't figure out how to pass a parameter in template.
This is a url pattern that takes argument.
path("<str:entry>",views.display_entry,name="entry")
corresponding view is:
def display_entry(request,entry):
text = str(util.get_entry(entry))
markdown = Markdown()
html = markdown.convert(text)
html_file = open(f"encyclopedia/templates/encyclopedia/{entry}.html",'w')
html_file.write(html)
html_file.close()
return render(request, f"encyclopedia/{entry}.html")
and template where I'm trying to access this view is -
<ul>
{% for entry in entries %}
<li><a href="{% url 'encyclopedia/entry' %}">{{ entry }}</a></li>
{% endfor %}
</ul>
CodePudding user response:
path("<str:entry>", views.display_entry, name="entry-detail")
{% for entry in entries %}
<a href="{% url 'entry-detail' entry %}">{{ entry }}</a>
{% endfor %}