From 705f08b190025689910342916669a0ed89cc5b18 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Tue, 11 Oct 2016 10:34:23 +0100 Subject: [PATCH] Done blog post detail --- blog/static/css/blog.css | 46 ++++++++++++++++++++++++++++ blog/templates/blog/base.html | 27 ++++++++++++++++ blog/templates/blog/post_detail.html | 13 ++++++++ blog/templates/blog/post_list.html | 26 ++++++---------- blog/urls.py | 1 + blog/views.py | 6 +++- 6 files changed, 101 insertions(+), 18 deletions(-) create mode 100644 blog/static/css/blog.css create mode 100644 blog/templates/blog/base.html create mode 100644 blog/templates/blog/post_detail.html diff --git a/blog/static/css/blog.css b/blog/static/css/blog.css new file mode 100644 index 0000000..e32a7d3 --- /dev/null +++ b/blog/static/css/blog.css @@ -0,0 +1,46 @@ +.page-header { + background-color: #ff9400; + margin-top: 0; + padding: 20px 20px 20px 40px; +} + +.page-header h1, .page-header h1 a, .page-header h1 a:visited, .page-header h1 a:active { + color: #ffffff; + font-size: 36pt; + text-decoration: none; +} + +.content { + margin-left: 40px; +} + +h1, h2, h3, h4 { + font-family: 'Lobster', cursive; +} + +.date { + color: #828282; +} + +.save { + float: right; +} + +.post-form textarea, .post-form input { + width: 100%; +} + +.top-menu, .top-menu:hover, .top-menu:visited { + color: #ffffff; + float: right; + font-size: 26pt; + margin-right: 20px; +} + +.post { + margin-bottom: 70px; +} + +.post h1 a, .post h1 a:visited { + color: #000000; +} diff --git a/blog/templates/blog/base.html b/blog/templates/blog/base.html new file mode 100644 index 0000000..4603b49 --- /dev/null +++ b/blog/templates/blog/base.html @@ -0,0 +1,27 @@ +{% load staticfiles %} + + + + Neil's blog + + + + + + + + + +
+
+
+ {% block content %} + {% endblock %} +
+
+
+ + + \ No newline at end of file diff --git a/blog/templates/blog/post_detail.html b/blog/templates/blog/post_detail.html new file mode 100644 index 0000000..18073a9 --- /dev/null +++ b/blog/templates/blog/post_detail.html @@ -0,0 +1,13 @@ +{% extends 'blog/base.html' %} + +{% block content %} +
+ {% if post.published_date %} +
+ {{ post.published_date }} +
+ {% endif %} +

{{ post.title }}

+

{{ post.text|linebreaksbr }}

+
+{% endblock %} \ No newline at end of file diff --git a/blog/templates/blog/post_list.html b/blog/templates/blog/post_list.html index b5f3995..eb1647a 100644 --- a/blog/templates/blog/post_list.html +++ b/blog/templates/blog/post_list.html @@ -1,21 +1,13 @@ - - - - Neil's blog - - - -
-

Django Girls Blog

-
+{% extends 'blog/base.html' %} +{% block content %} {% for post in posts %} -
-

Published: {{ post.published_date }}

-

{{ post.title }}

-

{{ post.text | linebreaksbr }}

+
+
+

published: {{ post.published_date }}

+

{{ post.title }}

+

{{ post.text|linebreaksbr }}

+
{% endfor %} - - - \ No newline at end of file +{% endblock %} \ No newline at end of file diff --git a/blog/urls.py b/blog/urls.py index eecfb5f..d58576a 100644 --- a/blog/urls.py +++ b/blog/urls.py @@ -3,4 +3,5 @@ from . import views urlpatterns = [ url(r'^$', views.post_list, name='post_list'), + url(r'^post/(?P\d+)/$', views.post_detail, name='post_detail'), ] \ No newline at end of file diff --git a/blog/views.py b/blog/views.py index 9a8aa8b..f1c9b68 100644 --- a/blog/views.py +++ b/blog/views.py @@ -1,7 +1,11 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from django.utils import timezone from .models import Post def post_list(request): posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date') return render(request, 'blog/post_list.html', {'posts': posts}) + +def post_detail(request, pk): + post = get_object_or_404(Post, pk=pk) + return render(request, 'blog/post_detail.html', {'post': post}) -- 2.34.1