Done blog post detail
authorNeil Smith <neil.git@njae.me.uk>
Tue, 11 Oct 2016 09:34:23 +0000 (10:34 +0100)
committerNeil Smith <neil.git@njae.me.uk>
Tue, 11 Oct 2016 09:34:23 +0000 (10:34 +0100)
blog/static/css/blog.css [new file with mode: 0644]
blog/templates/blog/base.html [new file with mode: 0644]
blog/templates/blog/post_detail.html [new file with mode: 0644]
blog/templates/blog/post_list.html
blog/urls.py
blog/views.py

diff --git a/blog/static/css/blog.css b/blog/static/css/blog.css
new file mode 100644 (file)
index 0000000..e32a7d3
--- /dev/null
@@ -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 (file)
index 0000000..4603b49
--- /dev/null
@@ -0,0 +1,27 @@
+{% load staticfiles %}
+<!DOCTYPE html>
+<html>
+<head>
+       <title>Neil's blog</title>
+       <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
+       <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
+       <link href="//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
+       <link rel="stylesheet" href="{% static 'css/blog.css' %}">
+</head>
+
+
+<body>
+       <div class="page-header">
+               <h1><a href="/">Django Girls Blog</a></h1>
+       </div>
+       <div class="content container">
+               <div class="row">
+                       <div class="col-md-8">
+                               {% block content %}
+                               {% endblock %}
+                       </div>
+               </div>
+       </div>
+</body>
+
+</html>
\ 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 (file)
index 0000000..18073a9
--- /dev/null
@@ -0,0 +1,13 @@
+{% extends 'blog/base.html' %}
+
+{% block content %}
+<div class="post">
+       {% if post.published_date %}
+               <div class="date">
+                       {{ post.published_date }}
+               </div>
+       {% endif %}
+       <h1>{{ post.title }}</h1>
+       <p>{{ post.text|linebreaksbr }}</p>
+</div>
+{% endblock %}
\ No newline at end of file
index b5f399523a213d495fe6fb4e0bc712c565dbe575..eb1647a5e1e304356185d1d82854b53e2d9bce29 100644 (file)
@@ -1,21 +1,13 @@
-<!DOCTYPE html>
-<html>
-<head>
-       <title>Neil's blog</title>
-</head>
-<body>
-
-<div>
-       <h1><a  href="">Django  Girls   Blog</a></h1>
-</div>
+{% extends 'blog/base.html' %}
 
+{% block content %}
 {% for post in posts %}
-       <div>
-       <p>Published: {{ post.published_date }}</p>
-       <h1><a href="">{{ post.title }}</a></h1>
-       <p>{{ post.text | linebreaksbr }}</p>
+<div class="post">
+       <div class="date">
+               <p>published: {{ post.published_date }}</p>
        </div>
+       <h1><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h1>
+       <p>{{ post.text|linebreaksbr }}</p>
+</div>
 {% endfor %}
-
-</body>
-</html>
\ No newline at end of file
+{% endblock %}
\ No newline at end of file
index eecfb5facd9d49b20b269246c0ff8195bbe4e864..d58576af277da014b320125d9e6ece59922b4bd2 100644 (file)
@@ -3,4 +3,5 @@ from . import views
 
 urlpatterns = [
        url(r'^$', views.post_list, name='post_list'),
+       url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),
 ]
\ No newline at end of file
index 9a8aa8ba3f34059e8440e9ea11ee36da4491e09d..f1c9b6826e28d894697ee9f61aed881d6dcd2983 100644 (file)
@@ -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})