From 520a95911abd002abf604a7479170cc900359cbb Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Wed, 5 Oct 2016 10:40:55 +0100 Subject: [PATCH] Added template to a view --- blog/templates/blog/post_list.html | 18 ++++++++---------- blog/views.py | 5 ++++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/blog/templates/blog/post_list.html b/blog/templates/blog/post_list.html index aa9d1d5..b5f3995 100644 --- a/blog/templates/blog/post_list.html +++ b/blog/templates/blog/post_list.html @@ -8,16 +8,14 @@

Django Girls Blog

-
-

published: 14.06.2014, 12:14

-

My first post

-

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 rmentum mass a justo sit amet risus.

-
-
-

published: 14.06.2014, 12:14

-

My second post

-

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.

-
+ +{% for post in posts %} +
+

Published: {{ post.published_date }}

+

{{ post.title }}

+

{{ post.text | linebreaksbr }}

+
+{% endfor %} \ No newline at end of file diff --git a/blog/views.py b/blog/views.py index 299ca35..9a8aa8b 100644 --- a/blog/views.py +++ b/blog/views.py @@ -1,4 +1,7 @@ from django.shortcuts import render +from django.utils import timezone +from .models import Post 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}) -- 2.34.1