Skip to content

Commit eb0f437

Browse files
author
yangxg
committed
完善注释,完善评论,完善模板和一些细节
1 parent 1c8297a commit eb0f437

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

blog/templatetags/blog_tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@register.simple_tag
99
def get_recent_posts(num=5):
10-
return Post.objects.all().order_by('-created_time')[:num]
10+
return Post.objects.all()[:num]
1111

1212

1313
@register.simple_tag

blog/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def index(request):
2121

2222

2323
def index(request):
24-
post_list = Post.objects.all().order_by('-created_time')
24+
post_list = Post.objects.all()
2525
return render(request, 'blog/index.html', context={'post_list': post_list})
2626

2727

@@ -63,11 +63,11 @@ def detail(request, pk):
6363
def archives(request, year, month):
6464
post_list = Post.objects.filter(created_time__year=year,
6565
created_time__month=month
66-
).order_by('-created_time')
66+
)
6767
return render(request, 'blog/index.html', context={'post_list': post_list})
6868

6969

7070
def category(request, pk):
7171
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)
7373
return render(request, 'blog/index.html', context={'post_list': post_list})

templates/base.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<div class="row">
3030
<div class="col-md-4 col-sm-5 col-xs-8">
3131
<div class="logo">
32-
<h1><a href="index.html"><b>Black</b> &amp; White</a></h1>
32+
<h1><a href="{% url 'blog:index' %}"><b>Black</b> &amp; White</a></h1>
3333
</div>
3434
</div><!-- col-md-4 -->
3535
<div class="col-md-8 col-sm-7 col-xs-4">
@@ -42,10 +42,10 @@ <h1><a href="index.html"><b>Black</b> &amp; White</a></h1>
4242

4343
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
4444
<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>
4949
</ul>
5050
</div><!-- /.navbar-collapse -->
5151
</nav>

templates/blog/detail.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
<header class="entry-header">
66
<h1 class="entry-title">{{ post.title }}</h1>
77
<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>
910
<span class="post-date"><a href="#"><time class="entry-date"
1011
datetime="{{ post.created_time }}">{{ post.created_time }}</time></a></span>
1112
<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>
1315
<span class="views-count"><a href="#">588 阅读</a></span>
1416
</div>
1517
</header>
1618
<div class="entry-content clearfix">
1719
{{ post.body|safe }}
1820
</div>
1921
</article>
20-
<section class="comment-area">
22+
<section class="comment-area" id="comment-area">
2123
<hr>
2224
<h3>发表评论</h3>
2325
<form action="{% url 'comments:post_comment' post.pk %}" method="post" class="comment-form">
@@ -47,7 +49,7 @@ <h3>发表评论</h3>
4749
</div> <!-- row -->
4850
</form>
4951
<div class="comment-list-panel">
50-
<h3>评论列表,共 <span>4</span> 条评论</h3>
52+
<h3>评论列表,共 <span>{{ post.comment_set.count }}</span> 条评论</h3>
5153
<ul class="comment-list list-unstyled">
5254
{% for comment in comment_list %}
5355
<li class="comment-item">

templates/blog/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ <h1 class="entry-title">
88
<a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
99
</h1>
1010
<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>
1213
<span class="post-date"><a href="#"><time class="entry-date"
1314
datetime="{{ post.created_time }}">{{ post.created_time }}</time></a></span>
1415
<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>
1719
</div>
1820
</header>
1921
<div class="entry-content clearfix">

0 commit comments

Comments
 (0)