Ok, I'm stuck and I don't know what I'm doing wrong. I have database and i need to fetch data from it and render it in HTML. I've watched few tutorials and it doesn't seem hard but it's not working for me. this is my view:
def get_all_subjects(request):
all_subjects = Predmeti.objects.all()
return render(request, 'home.html', {"Predmeti": all_subjects})
and this is home.html:
{% block content %}
{% if user.is_authenticated %}
Hi {{ user.email }}!
<p><a href="{% url 'logout' %}">logout</a></p>
<table>
{% for predmet in Predmeti %}
<tr>
<td>{{ predmet.ime }}</td>
<td>{{ predmet.kod }}</td>
<td>{{ predmet.bodovi }}</td>
<td>{{ predmet.izborni }} </td>
<td>
<form method="POST" action="{% url 'upisni list' id=predmet.id %}">
{% csrf_token %}
<button type="submit"> Dodaj</button>
</form>
</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>You are not logged in</p>
<a href="{% url 'login' %}">login</a> |
<a href="{% url 'signup' %}">signup</a>
{% endif %}
{% endblock %}
It just says hi to username. Any help is welcome
Predmetiyou pass is not well enough. Maybe there's a conflict with the name of your model or something like this. Have you tried a different name for the variable passed to the template?