Modified templates to display posts from database.

This commit is contained in:
lush2020
2023-03-30 19:02:36 -07:00
parent 8a77555b86
commit 4f801cb2c4
2 changed files with 11 additions and 2 deletions

View File

@@ -22,5 +22,12 @@
<h2><a href="">My second post</a></h2>
<p>Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut f.</p>
</div>
{% for post in posts %}
<div>
<p>published: {{ post.published_date }}</p>
<h1><a href="">{{ post.title }}</a></h1>
<p>{{ post.text|linebreaksbr }}</p>
</div>
{% endfor %}
</body>
</html>

View File

@@ -1,5 +1,7 @@
from django.shortcuts import render
from .models import Post
from django.utils import timezone
# Create your views here.
def post_list(request):
return render(request, 'blog/post_list.html', {})
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
return render(request, 'blog/post_list.html', {'posts': posts})