Django+Bootstrap+Mysql 搭建个人博客(四)
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>
{% 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 搭建个人博客(四)的更多相关文章
- Django+Bootstrap+Mysql 搭建个人博客(一)
1.1.环境搭建 (1)虚拟环境 mkvirtualenv website pip install django==1.11.7 (2)创建项目和app:website和blog (3)设置中文set ...
- Django+Bootstrap+Mysql 搭建个人博客(三)
3.1.分页功能 (1)views.py from django.core.paginator import Paginator,EmptyPage,PageNotAnInteger def make ...
- Django+Bootstrap+Mysql 搭建个人博客(五)
5.1.自定义403,404和500页面 (1)website/urls.py from blog import views as blog_views handler403 = blog_views ...
- Django+Bootstrap+Mysql 搭建个人博客(二)
2.1.博客首页设计 (1)settings.py MEDIA_ROOT = os.path.join(BASE_DIR,'media').replace("//","/ ...
- Django+Bootstrap+Mysql 搭建个人博客(六)
6.1.comments插件 (1)安装 pip install django-contrib-comments (02)settings INSTALLED_APPS = [ 'django.con ...
- Django+Bootstrap+Mysql 搭建个人博客 (六)
6.1.comments插件 (1)安装 pip install django-contrib-comments (02)settings INSTALLED_APPS = [ 'django.con ...
- Python Web开发:Django+BootStrap实现简单的博客项目
创建blog的项目结构 关于如何创建一个Django项目,请查看[Python Web开发:使用Django框架创建HolleWorld项目] 创建blog的数据模型 创建一个文章类 所有开发都是数据 ...
- django入门--django-blog-zinnia搭建个人博客
1.安装python 选择合适python2.7及以上版本安装https://www.python.org/downloads/ 2.建立虚拟环境 这不是必须的,但是建议使用,为每个项目单独引入依赖, ...
- Django两天搭建个人博客
传送门:https://github.com/1417766861/django-blog(可直接运行,上面有步骤) 效果: 首页: 侧栏: 详情页面: 修改头像,资料,文章发布: 支持添加标签拖拽 ...
随机推荐
- Mac安装nginx配置过程
mac电脑系统重装了,记录一下安装nginx的过程: 1.打开终端 2.安装Command Line tools xcode-select --install 3.安装brew命令 ruby -e & ...
- tensorflow卷积神经网络-【老鱼学tensorflow】
前面我们曾有篇文章中提到过关于用tensorflow训练手写2828像素点的数字的识别,在那篇文章中我们把手写数字图像直接碾压成了一个784列的数据进行识别,但实际上,这个图像是2828长宽结构的,我 ...
- python 10大算法之二 LogisticRegression 笔记
使用的包 import matplotlib.pyplot as plt import pandas as pd import numpy as npfrom sklearn import datas ...
- Codeforces 126B. Password (KMP)
<题目链接> 题目大意:给定一个字符串,从中找出一个前.中.后缀最长公共子串("中"代表着既不是前缀,也不是后缀的部分). 解题分析:本题依然是利用了KMP中next数 ...
- C++ MD5类封装
c++ md5 算法封装 md5.h #ifndef MD5_H #define MD5_H #include <string> #include <fstream> /* T ...
- Adams 2013自定义插件方法zz
1.Adams插件介绍 Adams的高级模块(如Controls控制模块.Vibration振动模块.Durability耐久性模块等)是以插件的形式集成在Adams软件中.通过Adams提供的插件管 ...
- 转载 CSDN 谈谈我对证券公司一些部门的理解(前、中、后台)
谈谈我对证券公司一些部门的理解(前.中.后台) 2018年02月08日 15:11:07 unirong 阅读数:2165 文中对各大部门的分析都是从作者多年经历总结出来的有感之谈,尤其是前台的6 ...
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习7
#include <iostream> #include <string> #include <cctype> using namespace std; int m ...
- java中的异常(一)
java异常的概念 执行期的错误(javac xxx.java) 运行期的错误(java xxx) 这里讲的是运行期出现的错误 class TestEx { public static void ma ...
- js实现八皇后,回溯法
八皇后问题:将八个皇后摆在一张8*8的国际象棋棋盘上,使每个皇后都无法吃掉别的皇后,一共有多少种摆法? 两个皇后不能同时在同一行,同一列,和斜对角线的位置上,使用回溯法解决. 从第一行选个位置开始放棋 ...