Please help, I tried tracing back my code by removing some part of it and putting it back in to see which one raised the error and this one was the one that raised the above error.
context = {
'items': 'Item.objects.all()'
}
This is from my django-views
from django.shortcuts import render
from .models import Item
def vendors(request):
return render(request, 'pages/vendors.html', {'title': 'Vendors'})
def items(request):
context = {
'items': Item.objects.all()
}
return render(request, context, 'pages/items.html', {'title': 'Items'})
def request(request):
return render(request, 'pages/request.html', {'title': 'Request'})
This is the items page I was trying to access.
{% extends "pages/base.html" %}
{% load humanize %}
{% block content %}
{% for item in items %}
<article class="media content-section">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="#">{{ item.requester }}</a>
<small class="text-muted">{{ item.date_requesteded|naturaltime }}</small>
</div>
<h2><a class="article-title" href="#">{{ item.name }}</a></h2>
<p class="article-content">{{ item.description }}</p>
</div>
</article>
{% endfor %}
{% endblock content %}
The other html page worked fine.
context = {
'items': Item.objects.all(),
'title': 'Items'
}
return render(request, 'pages/items.html', context)
While Alexander's answer is correct, it's important to know why in case someone comes across this post.
Django's render() function uses positional arguments in this order:
render(request, template_name, context)
and in OP's post, he passed the context variable twice.
More information in the official documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With