Skip to content

Commit 101de95

Browse files
author
yangxueguang
committed
标签云和文章归档
1 parent 53c0b2a commit 101de95

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

blog/templates/blog/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ <h4 class="panel-title">
7373
aria-labelledby="heading{{ forloop.counter }}">
7474
<div class="panel-body">
7575
{% for month in months %}
76-
<p>{{ month }} 月</p>
76+
<a href="{% url 'blog:archive' year month %}"><p>{{ month }} 月</p></a>
7777
{% endfor %}
7878
</div>
7979
</div>

blog/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
url(r'^article/(?P<article_id>\d+)$', views.ArticleDetailView.as_view(), name='detail'),
77
url(r'^category/(?P<cate_id>\d+)$', views.CategoryView.as_view(), name='category'),
88
url(r'^tag/(?P<tag_id>\d+)$', views.TagView.as_view(), name='tag'),
9+
url(r'^archive/(?P<year>\d+)/(?P<month>\d+)$', views.ArchiveView.as_view(), name='archive'),
910
]

blog/views.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,20 @@ def get_queryset(self):
6363
def get_context_data(self, **kwargs):
6464
kwargs['tag_list'] = Tag.objects.all().order_by('name')
6565
return super(TagView, self).get_context_data(**kwargs)
66+
67+
68+
class ArchiveView(ListView):
69+
template_name = "blog/index.html"
70+
context_object_name = "article_list"
71+
72+
def get_queryset(self):
73+
year = int(self.kwargs['year'])
74+
month = int(self.kwargs['month'])
75+
article_list = Article.objects.filter(created_time__year=year, created_time__month=month)
76+
for article in article_list:
77+
article.body = markdown2.markdown(article.body, extras=['fenced-code-blocks'], )
78+
return article_list
79+
80+
def get_context_data(self, **kwargs):
81+
kwargs['tag_list'] = Tag.objects.all().order_by('name')
82+
return super(ArchiveView, self).get_context_data(**kwargs)

db.sqlite3

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)