4.1.博客分类

(1)blog_tags.py

@register.simple_tag
def get_categories():
return Category.objects.all() @register.simple_tag
def get_entry_count_of_category(category_name):
return Entry.objects.filter(category__name=category_name).count()

(2)right_side_bar.html

 <div class="row">
<div class="widget">
<h3>分类:</h3>
{% get_categories as category_list %}
<ul class="list-group">
{% for category in category_list %}
<li class="list-group-item">
<a href="{% url 'blog:blog_category' category.id %}">{{ category.name }}</a>
<span class="badge">{% get_entry_count_of_category category.name %}</span>
</li>
{% endfor %}
</ul>
</div>
</div>

4.2.博客归档

(1)urls.py

url(r'^archives/(?P<year>[0-9]+)/(?P<month>[0-9]+)$', views.archives, name='blog_archives'),

(2)views.py

def archives(request, year, month):
entries = models.Entry.objects.filter(created_time__year=year, created_time__month=month)
page = request.GET.get('page', 1)
entry_list, paginator = make_paginator(entries, page)
page_data = pagination_data(paginator, page)
return render(request, 'blog/index.html', locals())

(3)blog_tags.py

@register.simple_tag
def archives():
return Entry.objects.dates('created_time', 'month', order='DESC') @register.simple_tag
def get_entry_count_of_date(year, month):
return Entry.objects.filter(created_time__year=year, created_time__month=month).count()

(4)right_side_bar.html

<div class="row">
<div class="widget">
<h3>归档:</h3>
{% archives as date_list %}
<ul class="list-group">
{% for date in date_list %}
<li class="list-group-item">
<a href="{% url 'blog:blog_archives' date.year date.month %}">
<i class="glyphicon glyphicon-chevron-right"></i>
{{ date.year }} 年 {{ date.month }} 月
<span class="badge">{% get_entry_count_of_date date.year date.month %}</span>
</a> </li>
{% endfor %}
</ul>
</div>
</div>

4.3.标签云

(1)blog_tags.py

@register.simple_tag
def get_tags():
return Tag.objects.all()

(2)right_side_bar.html

<div class="row">
<div class="widget" >
<h3>标签云:</h3>
{% get_tags as tag_list %}
{% for tag in tag_list %}
<a href="{% url 'blog:blog_tag' tag.id %}" style="font-size: 20px;">
<span style="padding: 5px;" class="label {% cycle 'label-default' 'label-primary' 'label-success' 'label-info' 'label-warning' 'label-danger' %}">{{ tag.name }}</span>
</a>&nbsp;
{% endfor %}
</div>
</div>

4.4.RSS订阅

(1)blog/feed.py

from django.contrib.syndication.views import Feed
# from django.urls import reverse
from .models import Entry class LatestEntriesFeed(Feed):
title = "Zhang_derek的博客"
link = "/siteblogs/"
description = "zhang_derek的最新博客文章!" def items(self):
return Entry.objects.order_by('-created_time')[:5] def item_title(self, item):
return item.title def item_description(self, item):
return item.abstract

(2)website/urls.py

from blog.feed import LatestEntriesFeed

url(r'^latest/feed/$', LatestEntriesFeed()),    #RSS订阅

(3)right_side_bar.html

<div class="row">
<div class="rss">
<a href="/latest/feed/"><i class="glyphicon glyphicon-plus"></i>RSS 订阅</a>
</div>
</div>

Django+Bootstrap+Mysql 搭建个人博客(四)的更多相关文章

  1. Django+Bootstrap+Mysql 搭建个人博客(一)

    1.1.环境搭建 (1)虚拟环境 mkvirtualenv website pip install django==1.11.7 (2)创建项目和app:website和blog (3)设置中文set ...

  2. Django+Bootstrap+Mysql 搭建个人博客(三)

    3.1.分页功能 (1)views.py from django.core.paginator import Paginator,EmptyPage,PageNotAnInteger def make ...

  3. Django+Bootstrap+Mysql 搭建个人博客(五)

    5.1.自定义403,404和500页面 (1)website/urls.py from blog import views as blog_views handler403 = blog_views ...

  4. Django+Bootstrap+Mysql 搭建个人博客(二)

    2.1.博客首页设计 (1)settings.py MEDIA_ROOT = os.path.join(BASE_DIR,'media').replace("//","/ ...

  5. Django+Bootstrap+Mysql 搭建个人博客(六)

    6.1.comments插件 (1)安装 pip install django-contrib-comments (02)settings INSTALLED_APPS = [ 'django.con ...

  6. Django+Bootstrap+Mysql 搭建个人博客 (六)

    6.1.comments插件 (1)安装 pip install django-contrib-comments (02)settings INSTALLED_APPS = [ 'django.con ...

  7. Python Web开发:Django+BootStrap实现简单的博客项目

    创建blog的项目结构 关于如何创建一个Django项目,请查看[Python Web开发:使用Django框架创建HolleWorld项目] 创建blog的数据模型 创建一个文章类 所有开发都是数据 ...

  8. django入门--django-blog-zinnia搭建个人博客

    1.安装python 选择合适python2.7及以上版本安装https://www.python.org/downloads/ 2.建立虚拟环境 这不是必须的,但是建议使用,为每个项目单独引入依赖, ...

  9. Django两天搭建个人博客

    传送门:https://github.com/1417766861/django-blog(可直接运行,上面有步骤) 效果: 首页: 侧栏: 详情页面: 修改头像,资料,文章发布: 支持添加标签拖拽 ...

随机推荐

  1. Sublime Text3 & MinGW & LLVM CLang 安装配置C-C++编译环境

    Sublime Text是一款强大的跨平台代码编辑器,小巧而且丰富实用的功能是Visual Studio不能比拟的,但是编译运行是一个软肋,本文通过在sublime中配置g++编译器实现程序的编译功能 ...

  2. 【转发】如何使用NPM?CNPM又是什么?

    转发:https://www.jianshu.com/p/f581cf9360a2 背景介绍 什么是npm? npm(node package manager)是nodejs的包管理器,用于node插 ...

  3. web-storage-cache 使用JS数据缓存

    https://github.com/WQTeam/web-storage-cache 使用WebStorageCache,只要在页面上引入下面代码即可. <script src="s ...

  4. Exp3 免杀原理与实践 20164302 王一帆

    1 实践内容 1.1 正确使用msf编码器(0.5分),msfvenom生成如jar之类的其他文件(0.5分),veil-evasion(0.5分),加壳工具(0.5分),使用shellcode编程( ...

  5. iOS 获取app进程被杀死事件

    程序被用户双击上滑杀死后,就对app做一些特殊的处理 下面的方法可以获取到用户双击上滑杀死的事件 - (void)applicationDidEnterBackground:(UIApplicatio ...

  6. BZOJ 4665

    orz gery 一发rk1真有趣(其实我没想着常数优化 inline int sqr(int x){return 1ll*x*x%mo;} const int N=2011; int n,a[N], ...

  7. 微信跳转,手机WAP浏览器一键超级跳转微信指定页面

    微信跳转,手机WAP浏览器一键超级跳转微信指定页面 这篇文章主要介绍了如何在手机浏览器wap网页中点击链接跳转到微信界面,需要的朋友可以参考下 先说第一种,最简单的唤起微信协议,weixin://主流 ...

  8. 导航栏动态添加act属性

    最近做了一个网站,需要设置导航栏的act属性,这里需要用到addClass以及removeClass: $('#topName li').removeClass('active'); $(this). ...

  9. 马昕璐 201771010118《面向对象程序设计(java)》第十五周学习总结

    第一部分:理论知识学习部分 JAR文件:将.class文件压缩打包为.jar文件后,使用ZIP压缩格式,GUI界面程序就可以直接双击图标运行. 既可以包含类文件,也可以包含诸如图像和声音这些其它类型的 ...

  10. [LeetCode] New 21 Game 新二十一点游戏

    Alice plays the following game, loosely based on the card game "21". Alice starts with 0 p ...