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(可直接运行,上面有步骤) 效果: 首页: 侧栏: 详情页面: 修改头像,资料,文章发布: 支持添加标签拖拽 ...
随机推荐
- Vue 2.6 中部分引入 TypeScript 的方法
在 Vue 与 Cesium 联合开发的过程中,我发现很多 Cesium 代码不宜直接写在 .vue 文件中.同时由于 Cesium 库较为复杂,不借助 TypeScript 的静态类型会导致代码难维 ...
- Python学习(四十二)—— Djago-model进阶
一.QuerySet 可切片 使用Python 的切片语法来限制查询集记录的数目 .它等同于SQL 的LIMIT 和OFFSET 子句. Entry.objects.all()[:5] # (LIMI ...
- pycharm的list中clear的应用
#清空的意思 li = [11,22,33,44] li.clear() print(li) #输出[],就是把列表清空
- 一、OpenStack环境准备及共享组件安装
一.OpenStack部署环境准备: 1.关闭防火墙所有虚拟机都要操作 # setenforce 0 # systemctl stop firewalld 2.域名解析所有虚拟机都要操作 # cat ...
- Metasploit中aggregator插件无法使用
Metasploit中aggregator插件无法使用 aggregator是Metasploit自带的一个插件,用来管理会话Session.该插件使用metasploit-aggreator库. ...
- [OC] UITableView 与 UItableViewCell 的使用
UITableView //UIViewController里添加一个UITableView @interface ViewController : UIViewController<UITa ...
- web开发中如何使用引用字体
1.在style中添加代码: @font-face { font-family: mFont; src: url('../font/crapaud_petit.ttf'); } 2.使用 <h1 ...
- git cannot lock ref
参考博客:https://blog.csdn.net/lindexi_gd/article/details/79213042 错误原文: cannot lock ref ‘refs/remotes/o ...
- OI暑假集训游记
莞中OI集训游记 Written BY Jum Leon. I 又是一载夏,本蒟蒻以特长生考入莞中,怀着忐忑的心情到了8月,是集训之际.怀着对算法学习的向往心情被大佬暴虐的一丝恐惧来到了 ...
- Python操作Excel, 开发和调用接口,发送邮件
笔记: 上周回顾: 模块: 导入模块的顺序 lyl.py # def hhh(): pass name = 'lyl' a.py import lyl import sys from lyl impo ...