File tree Expand file tree Collapse file tree 5 files changed +42
-2
lines changed Expand file tree Collapse file tree 5 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 1
1
{% extends "base.html" %}
2
+ {% load blog_tags %}
2
3
3
4
{% block title %}{{ post.title }}{% endblock %}
4
5
@@ -7,7 +8,7 @@ <h1>{{ post.title }}</h1>
7
8
< p class ="date ">
8
9
Published {{ post.publish }} by {{ post.author }}
9
10
</ p >
10
- {{ post.body|linebreaks }}
11
+ {{ post.body|markdown }}
11
12
< p >
12
13
< a href ="{% url "blog:post_share " post.id %}">
13
14
Share this post
Original file line number Diff line number Diff line change
1
+ < ul >
2
+ {% for post in latest_posts %}
3
+ < li >
4
+ < a href ="{{ post.get_absolute_url }} "> {{ post.title }}</ a >
5
+ </ li >
6
+ {% endfor %}
7
+ </ ul >
Original file line number Diff line number Diff line change 1
1
{% extends "base.html" %}
2
+ {% load blog_tags %}
2
3
3
4
{% block title %}My Blog{% endblock %}
4
5
26
27
< p class ="date ">
27
28
Published {{ post.publish }} by {{ post.author }}
28
29
</ p >
29
- {{ post.body|truncatewords :30|linebreaks }}
30
+ {{ post.body|markdown|truncatewords_html :30 }}
30
31
{% endfor %}
31
32
{% include "pagination.html" with page=posts %}
32
33
{% endblock %}
Original file line number Diff line number Diff line change
1
+ from django import template
2
+ from django .db .models import Count
3
+ from django .utils .safestring import mark_safe
4
+ import markdown
5
+ from ..models import Post
6
+
7
+
8
+ register = template .Library ()
9
+
10
+
11
+ @register .simple_tag
12
+ def total_posts ():
13
+ return Post .published .count ()
14
+
15
+
16
+ @register .inclusion_tag ('blog/post/latest_posts.html' )
17
+ def show_latest_posts (count = 5 ):
18
+ latest_posts = Post .published .order_by ('-publish' )[:count ]
19
+ return {'latest_posts' : latest_posts }
20
+
21
+
22
+ @register .simple_tag
23
+ def get_most_commented_posts (count = 5 ):
24
+ return Post .published .annotate (
25
+ total_comments = Count ('comments' )
26
+ ).order_by ('-total_comments' )[:count ]
27
+
28
+
29
+ @register .filter (name = 'markdown' )
30
+ def markdown_format (text ):
31
+ return mark_safe (markdown .markdown (text ))
You can’t perform that action at this time.
0 commit comments