Skip to content

Commit e8ca000

Browse files
committed
Added view and template for detailed blog post as well as CSS for the site.
1 parent 5748733 commit e8ca000

File tree

6 files changed

+115
-25
lines changed

6 files changed

+115
-25
lines changed

blog/static/css/blog.css

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
h1 a {
2+
color: #768584;
3+
font-family: 'Lobster';
4+
}
5+
6+
body {
7+
padding-left: 15px;
8+
}
9+
10+
.page-header {
11+
background-color: #ff9400;
12+
margin-top: 0;
13+
padding: 20px 20px 20px 40px;
14+
}
15+
16+
.page-header h1, .page-header h1 a, .page-header h1 a:visited, .page-header h1 a:active {
17+
color: #ffffff;
18+
font-size: 36pt;
19+
text-decoration: none;
20+
}
21+
22+
.content {
23+
margin-left: 40px;
24+
}
25+
26+
h1, h2, h3, h4 {
27+
font-family: 'Lobster', cursive;
28+
}
29+
30+
.date {
31+
float: right;
32+
color: #828282;
33+
}
34+
35+
.save {
36+
float: right;
37+
}
38+
39+
.post-form textarea, .post-form input {
40+
width: 100%;
41+
}
42+
43+
.top-menu, .top-menu:hover, .top-menu:visited {
44+
color: #ffffff;
45+
float: right;
46+
font-size: 26pt;
47+
margin-right: 20px;
48+
}
49+
50+
.post {
51+
margin-bottom: 70px;
52+
}
53+
54+
.post h1 a, .post h1 a:visited {
55+
color: #000000;
56+
}

blog/templates/blog/base.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{% load staticfiles %}
2+
3+
<html>
4+
<head>
5+
<title>Malins blog!</title>
6+
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
7+
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
8+
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
9+
<link href="http://fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
10+
</head>
11+
<body>
12+
<body>
13+
<div class="page-header">
14+
<h1><a href="/">Django Girls Blog</a></h1>
15+
</div>
16+
<div class="content container">
17+
<div class="row">
18+
<div class="col-md-8">
19+
{% block content %}
20+
{% endblock %}
21+
</div>
22+
</div>
23+
</div>
24+
</body>
25+
</html>

blog/templates/blog/post_detail.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends 'blog/base.html' %}
2+
3+
{% block content %}
4+
<div class="post">
5+
{% if post.published_date %}
6+
<div class="date">
7+
{{ post.published_date }}
8+
</div>
9+
{% endif %}
10+
<h1>{{ post.title }}</h1>
11+
<p>{{ post.text|linebreaks }}</p>
12+
</div>
13+
{% endblock %}

blog/templates/blog/post_list.html

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
<html>
2-
<head>
3-
<title>Malins blog!</title>
4-
</head>
5-
<body>
6-
<div>
7-
<h1><a href="">MALIN - Django Girls Blog</a></h1>
8-
</div>
1+
{% extends 'blog/base.html' %}
92

10-
{% for post in posts %}
11-
<div>
12-
<p>published: {{ post.published_date }}</p>
13-
<h1><a href="">{{ post.title }}</a></h1>
14-
<p>{{ post.text|linebreaks }}</p>
15-
</div>
16-
{% endfor %}
17-
18-
<div>
19-
<p>published: 14.06.2014, 12:14</p>
20-
<h2><a href="">My second post</a></h2>
21-
<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>
22-
</div>
23-
</body>
24-
</html>
3+
{% block content %}
4+
{% for post in posts %}
5+
<div class="post">
6+
<div class="date">
7+
{{ post.published_date }}
8+
</div>
9+
<h1><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h1>
10+
<p>{{ post.text|linebreaks }}</p>
11+
</div>
12+
{% endfor %}
13+
{% endblock %}

blog/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from django.conf.urls import url
1+
from django.conf.urls import include, url
22
from . import views
33

44
urlpatterns = [
55
url(r'^$', views.post_list, name='post_list'),
6+
url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail, name='post_detail'),
67
]
78

blog/views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
from django.shortcuts import render
22
from django.utils import timezone
33
from .models import Post
4+
from django.shortcuts import render, get_object_or_404
45

56
def post_list(request):
67
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
7-
return render(request, 'blog/post_list.html', {'posts': posts})
8+
return render(request, 'blog/post_list.html', {'posts': posts})
9+
10+
11+
def post_detail(request, pk):
12+
post = get_object_or_404(Post, pk=pk)
13+
return render(request, 'blog/post_detail.html', {'post': post})

0 commit comments

Comments
 (0)