2
2
3
3
from django .shortcuts import render , get_object_or_404
4
4
5
+ from comments .forms import CommentForm
5
6
from .models import Post , Category
6
7
7
8
"""
@@ -25,6 +26,8 @@ def index(request):
25
26
return render (request , 'blog/index.html' , context = {'post_list' : post_list })
26
27
27
28
29
+ """
30
+ 增加了评论功能后需要相应地更新 detail 函数,更新后的函数见下边。
28
31
def detail(request, pk):
29
32
post = get_object_or_404(Post, pk=pk)
30
33
post.body = markdown.markdown(post.body,
@@ -35,6 +38,25 @@ def detail(request, pk):
35
38
])
36
39
return render(request, 'blog/detail.html', context={'post': post})
37
40
41
+ """
42
+
43
+
44
+ def detail (request , pk ):
45
+ post = get_object_or_404 (Post , pk = pk )
46
+ post .body = markdown .markdown (post .body ,
47
+ extensions = [
48
+ 'markdown.extensions.extra' ,
49
+ 'markdown.extensions.codehilite' ,
50
+ 'markdown.extensions.toc' ,
51
+ ])
52
+ form = CommentForm ()
53
+ comment_list = post .comment_set .all ()
54
+ context = {'post' : post ,
55
+ 'form' : form ,
56
+ 'comment_list' : comment_list
57
+ }
58
+ return render (request , 'blog/detail.html' , context = context )
59
+
38
60
39
61
def archives (request , year , month ):
40
62
post_list = Post .objects .filter (created_time__year = year , created_time__month = month )
0 commit comments