I'm running a Jango Girls tutorial but it's not working well
First of all, this is the error.
NameError at / name 'posts ' is not defined
#mysite/views.py
from django.shortcuts import render
from django.utils import timezone
from .models import Post
# # Create your views here.
def post_list(request):
Posts = Post.objects.filter(pub_date__lte = timezone.now()).order_by('pub_date')
return render(request, 'mysite/post_list.html', {'posts':posts})
For your information, mysite is an application...
The following are template files...
<html>
<head>
<title>Django Girls blog</title>
</head>
<body>
<div>
<h1><a href="">Django Girls Blog</a></h1>
</div>
{% {% for post in posts %}
<div>
<p>published: {{ post.pub_date }}</p>
<h1><a href="">{{ post.product }}</a></h1>
<p>{{ post.description|linebreaksbr }}</p>
</div>
{% {% endfor %}
</body>
</html>
I don't know if it's a simple typo or a different problem, but if you look at the code,
def post_list(request):
Posts = Post.objects.filter(pub_date__lte = timezone.now()).order_by('pub_date')
return render(request, 'mysite/post_list.html', {'posts':posts})
# Posts, not posts
I think this is a problem.
You wrote the Posts variable incorrectly as posts
Thank you so much for your answers Haha
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.