File tree Expand file tree Collapse file tree 5 files changed +20
-16
lines changed Expand file tree Collapse file tree 5 files changed +20
-16
lines changed Original file line number Diff line number Diff line change 7
7
8
8
@register .simple_tag
9
9
def get_recent_posts (num = 5 ):
10
- return Post .objects .all (). order_by ( '-created_time' ) [:num ]
10
+ return Post .objects .all ()[:num ]
11
11
12
12
13
13
@register .simple_tag
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ def index(request):
21
21
22
22
23
23
def index (request ):
24
- post_list = Post .objects .all (). order_by ( '-created_time' )
24
+ post_list = Post .objects .all ()
25
25
return render (request , 'blog/index.html' , context = {'post_list' : post_list })
26
26
27
27
@@ -63,11 +63,11 @@ def detail(request, pk):
63
63
def archives (request , year , month ):
64
64
post_list = Post .objects .filter (created_time__year = year ,
65
65
created_time__month = month
66
- ). order_by ( '-created_time' )
66
+ )
67
67
return render (request , 'blog/index.html' , context = {'post_list' : post_list })
68
68
69
69
70
70
def category (request , pk ):
71
71
cate = get_object_or_404 (Category , pk = pk )
72
- post_list = Post .objects .filter (category = cate ). order_by ( '-created_time' )
72
+ post_list = Post .objects .filter (category = cate )
73
73
return render (request , 'blog/index.html' , context = {'post_list' : post_list })
Original file line number Diff line number Diff line change 29
29
< div class ="row ">
30
30
< div class ="col-md-4 col-sm-5 col-xs-8 ">
31
31
< div class ="logo ">
32
- < h1 > < a href ="index.html "> < b > Black</ b > & White</ a > </ h1 >
32
+ < h1 > < a href ="{% url 'blog: index' %} "> < b > Black</ b > & White</ a > </ h1 >
33
33
</ div >
34
34
</ div > <!-- col-md-4 -->
35
35
< div class ="col-md-8 col-sm-7 col-xs-4 ">
@@ -42,10 +42,10 @@ <h1><a href="index.html"><b>Black</b> & White</a></h1>
42
42
43
43
< div class ="collapse navbar-collapse " id ="bs-example-navbar-collapse-1 ">
44
44
< ul class ="nav navbar-nav navbar-right ">
45
- < li class ="cl-effect-11 "> < a href ="index.html " data-hover ="首页 "> 首页</ a > </ li >
46
- < li class ="cl-effect-11 "> < a href ="full-width.html " data-hover ="博客 "> 博客</ a > </ li >
47
- < li class ="cl-effect-11 "> < a href ="about.html " data-hover ="关于 "> 关于</ a > </ li >
48
- < li class ="cl-effect-11 "> < a href ="contact.html " data-hover ="联系 "> 联系</ a > </ li >
45
+ < li class ="cl-effect-11 "> < a href ="{% url 'blog: index' %} " data-hover ="首页 "> 首页</ a > </ li >
46
+ < li class ="cl-effect-11 "> < a href ="# " data-hover ="博客 "> 博客</ a > </ li >
47
+ < li class ="cl-effect-11 "> < a href ="# " data-hover ="关于 "> 关于</ a > </ li >
48
+ < li class ="cl-effect-11 "> < a href ="# " data-hover ="联系 "> 联系</ a > </ li >
49
49
</ ul >
50
50
</ div > <!-- /.navbar-collapse -->
51
51
</ nav >
Original file line number Diff line number Diff line change 5
5
< header class ="entry-header ">
6
6
< h1 class ="entry-title "> {{ post.title }}</ h1 >
7
7
< div class ="entry-meta ">
8
- < span class ="post-category "> < a href ="# "> {{ post.category.name }}</ a > </ span >
8
+ < span class ="post-category ">
9
+ < a href ="{% url 'blog:category' post.category.pk %} "> {{ post.category.name }}</ a > </ span >
9
10
< span class ="post-date "> < a href ="# "> < time class ="entry-date "
10
11
datetime ="{{ post.created_time }} "> {{ post.created_time }}</ time > </ a > </ span >
11
12
< span class ="post-author "> < a href ="# "> {{ post.author }}</ a > </ span >
12
- < span class ="comments-link "> < a href ="# "> 4 评论</ a > </ span >
13
+ < span class ="comments-link ">
14
+ < a href ="{{ post.get_absolute_url }}#comment-area "> {{ post.comment_set.count }} 评论</ a > </ span >
13
15
< span class ="views-count "> < a href ="# "> 588 阅读</ a > </ span >
14
16
</ div >
15
17
</ header >
16
18
< div class ="entry-content clearfix ">
17
19
{{ post.body|safe }}
18
20
</ div >
19
21
</ article >
20
- < section class ="comment-area ">
22
+ < section class ="comment-area " id =" comment-area " >
21
23
< hr >
22
24
< h3 > 发表评论</ h3 >
23
25
< form action ="{% url 'comments:post_comment' post.pk %} " method ="post " class ="comment-form ">
@@ -47,7 +49,7 @@ <h3>发表评论</h3>
47
49
</ div > <!-- row -->
48
50
</ form >
49
51
< div class ="comment-list-panel ">
50
- < h3 > 评论列表,共 < span > 4 </ span > 条评论</ h3 >
52
+ < h3 > 评论列表,共 < span > {{ post.comment_set.count }} </ span > 条评论</ h3 >
51
53
< ul class ="comment-list list-unstyled ">
52
54
{% for comment in comment_list %}
53
55
< li class ="comment-item ">
Original file line number Diff line number Diff line change @@ -8,12 +8,14 @@ <h1 class="entry-title">
8
8
< a href ="{{ post.get_absolute_url }} "> {{ post.title }}</ a >
9
9
</ h1 >
10
10
< div class ="entry-meta ">
11
- < span class ="post-category "> < a href ="# "> {{ post.category.name }}</ a > </ span >
11
+ < span class ="post-category ">
12
+ < a href ="{% url 'blog:category' post.category.pk %} "> {{ post.category.name }}</ a > </ span >
12
13
< span class ="post-date "> < a href ="# "> < time class ="entry-date "
13
14
datetime ="{{ post.created_time }} "> {{ post.created_time }}</ time > </ a > </ span >
14
15
< span class ="post-author "> < a href ="# "> {{ post.author }}</ a > </ span >
15
- < span class ="comments-link "> < a href ="# "> 4 评论</ a > </ span >
16
- < span class ="views-count "> < a href ="# "> 588 阅读</ a > </ span >
16
+ < span class ="comments-link ">
17
+ < a href ="{{ post.get_absolute_url }}#comment-area "> {{ post.comment_set.count }} 评论</ a > </ span >
18
+ < span class ="views-count "> < a href ="{{ post.get_absolute_url }} "> 588 阅读</ a > </ span >
17
19
</ div >
18
20
</ header >
19
21
< div class ="entry-content clearfix ">
You can’t perform that action at this time.
0 commit comments