When I try to use data from a dictionary, I get the error:
'tuple' object has no attribute 'get'
This happens when I click on a link that should take me to the page of the entry. The entry is a Markdown file that I get from util.get_entry(title).
How do I access data from a dictionary in my HTML template (entry.html)? Do I need to convert the Markdown into HTML?
entry.html:
{% extends "encyclopedia/layout.html" %}
<!-- {% load static %} -->
{% block title %}
{{ name }}
{% endblock %}
{% block style %}{% endblock %}
{% block body %}
<div class="left">{{ entry }}</div>
<div class="right">
<a href="{% url 'edit' %}">
<button class="edit">Edit</button>
</a>
</div>
{% endblock %}
views.py:
from . import util
def entry(request, name):
if util.get_entry(name) is not None:
return render(request, 'encyclopedia/entry.html'), {
'entry': util.get_entry(name),
'name': name
}
else:
return render(request, "encyclopedia/404.html")
urls.py:
path('<str:name>', views.entry, name='entry'),
>Solution :
You are not passing the dict in parameters. Please use this
from . import util
def entry(request, name):
if util.get_entry(name) is not None:
context ={
'entry': util.get_entry(name),
'name': name
}
return render(request, 'encyclopedia/entry.html',context)
else:
return render(request, "encyclopedia/404.html")