BBS 项目(四)
BBS 项目(四)
首页布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blog-index</title>
<script src="/static/element/jQuery3.4.js"></script>
<script src="/static/element/bootstrap.min.js"></script>
<link rel="stylesheet" href="/static/element/bootstrap.min.css">
<link rel="stylesheet" href="/static/element/bootstrap.min.css.map">
<link rel="stylesheet" href="/static/element/font-awesome-4.7.0/css/font-awesome.css">
<style>
footer#footer {
padding-top: 32px;
padding-bottom: 32px;
display: flex;
flex-direction: column;
align-items: center;
color: #888;
background-color: #f3f3f3;
font-size: 13px;
font-weight: 400;
text-align: center;
}
footer {
display: block;
}
body {
font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
font-weight: normal;
background-color: #fcf9f9;
}
.article_footer{
margin-right: 10px;
}
#underline{
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container-fluid">
{# 头部 #}
<div class="head">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<li class="navbar-branding">
<a href="/index/" class="navbar-brand" title="开发者的网上家园" role="banner">
博客园
</a>
</li>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="/index/">首页 <span class="sr-only">(current)</span></a></li>
<li><a href="https://news.cnblogs.com/">新闻</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
aria-haspopup="true" aria-expanded="false">发现 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="https://zzk.cnblogs.com/">找找看</a></li>
<li><a href="#">收藏</a></li>
<li><a href="https://www.lagou.com/">招聘</a></li>
<li role="separator" class="divider"></li>
<li><a href="/login/">个人园子</a></li>
</ul>
</li>
</ul>
{% if request.user.is_authenticated %}
<ul class="nav navbar-nav navbar-right">
<li><a href="#">{{ request.user.username }}</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
aria-haspopup="true" aria-expanded="false">更多操作 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="/">个人主页</a></li>
<li><a href="#">设置</a></li>
<li><a href="admin">后台管理</a></li>
<li role="separator" class="divider"></li>
<li><a href="/logout/">退出</a></li>
</ul>
</li>
</ul>
{% else %}
<ul class="nav navbar-nav navbar-right">
<li><a href="/login/">登录</a></li>
<li><a href="/register/">注册</a></li>
</ul>
{% endif %}
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
{# 主体 #}
<div class="body row">
{# 左侧 #}
<div class="col-md-2">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Panel title</h3>
</div>
<div class="panel-body">
Panel content
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Panel title</h3>
</div>
<div class="panel-body">
Panel content
</div>
</div>
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title">Panel title</h3>
</div>
<div class="panel-body">
Panel content
</div>
</div>
</div>
{# 中间 #}
<div class="col-md-7">
<div class="lunbotu">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
{% for banner in banner_list %}
{% if forloop.first %}
<div class="item active">
<img src="{{ banner.url }}" alt="首页图">
{# <div class="carousel-caption">#}
{# {{ banner.name }}#}
{# </div>#}
</div>
{% else %}
<div class="item ">
<img src="{{ banner.url }}" alt="首页图">
</div>
{% endif %}
{% endfor %}
</div>
{# 轮播图按钮 #}
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span aria-hidden="true"><i class="fa fa-angle-double-left fa-3x" style="margin-top: 180px"></i></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span aria-hidden="true"><i class="fa fa-angle-double-right fa-3x" style="margin-top: 180px"></i></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
{# 文章 #}
<div class="article" style="margin-top: 30px">
{% for article in article_list %}
<div>
<h4 class="media-heading"><a href="" id="underline">{{ article.title }}</a></h4>
<div class="media">
<div class="media-left media-middle">
<a href="#">
<img class="media-object" src="/media/{{ article.blog.userinfo.avatar }}" alt="用户主页头像" height="50px" width="50px">
{# <img class="media-object" src="/static/img/96327268.jpg" alt="用户主页头像" height="50px" width="50px">#}
</a>
</div>
<div class="media-body">
{{ article.desc }}
</div>
<div style="margin-top: 10px">
<span class="article_footer"><a href="" class="table-hover" >{{ article.blog.userinfo.username }}</a></span>
<span class="article_footer">{{ article.create_time|date:'Y-m-d H:i:s' }}</span>
{# <span class="glyphicon glyphicon-thumbs-up article_footer"> {{ article.up_num }}</span>#}
<span class="article_footer"><a href=""><i class="fa fa-thumbs-up fa-lg"></i></a> {{ article.up_num }}</span>
<span class="article_footer"><a href=""><i class="fa fa-thumbs-down fa-lg"></i></a> {{ article.down_num }}</span>
<span class='article_footer'><a href=""><i class="fa fa-comment fa-lg"></i></a> {{ article.commit_num }}</span>
</div>
</div>
<hr>
</div>
{% endfor %}
</div>
</div>
{# 右侧 #}
<div class="col-md-3">
<ul class="list-group">
<li class="list-group-item">Cras justo odio</li>
<li class="list-group-item">Dapibus ac facilisis in</li>
<li class="list-group-item">Morbi leo risus</li>
<li class="list-group-item">Porta ac consectetur ac</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
</div>
</div>
{# 页脚 #}
<div>
<br><br><br><br><br>
</div>
<div class="footer text-center" style="background-color: rgb(243,243,243)">
<footer id="footer" class="footer">
<div>
<!--done-->
Copyright 2022 HammerZe
<br><span id="poweredby">Powered by .NET 6 on Kubernetes</span>
<span class="esa-copyright">& Theme <a href="https://github.com/esofar/cnblogs-theme-silence"
target="_blank">Silence v3.0.0</a></span></div>
</footer>
</div>
</div>
</body>
</html>
个人头像显示
1 开启media
-配置文件
MEDIA_ROOT=os.path.join(BASE_DIR,'media')
-路由
re_path('^media/(?P<path>.*?)$', serve,kwargs={'document_root':settings.MEDIA_ROOT}),
-前端:
<img class="media-object" src="media/{{ article.blog.userinfo.avatar }}" alt="..." height="60px" width="60px">
个人站点路由设计
1 路由一定要放在最后
re_path('^(?P<username>\w+)$', views.personal_site),
个人站点页面设计
base.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>
{% block title %}
{% endblock %}
</title>
<script src="/static/jquery-3.3.1.js"></script>
<script src="/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/static/bootstrap-3.3.7-dist/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/font-awesome-4.7.0/css/font-awesome.min.css">
{% block js %}
{% endblock %}
</head>
<body>
<div class="head" style="margin-bottom: 10px">
<div style="height: 120px;background-color: #1b6d85">
<div class="row">
<div class="col-md-2" style="font-size: 30px;color: white;margin: 20px">
{% block site_name %}
{% endblock %}
</div>
</div>
<div class="row">
<div class="pull-right" style="margin-right: 20px">
<span><a href="">后台管理</a></span>
<span>首页</span>
<span>订阅</span>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
{% block left %}
{% endblock %}
{% block main %}
{% endblock %}
</div>
</div>
</body>
</html>
site.html
{% extends 'base.html' %}
{% block title %}
{{ user.username }}-博客园
{% endblock %}
{% block site_name %}
{{ user.blog.site_name }}
{% endblock %}
{% block left %}
<div class="col-md-2">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">我的标签</h3>
</div>
<div class="panel-body">
{% for tag in tag_list %}
<p><a href="">{{ tag.1 }}({{ tag.0 }})</a></p>
{% endfor %}
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">我的分类</h3>
</div>
<div class="panel-body">
{% for category in category_list %}
<p><a href="">{{ category.name }}({{ category.count }})</a></p>
{% endfor %}
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">随笔档案</h3>
</div>
<div class="panel-body">
{% for month in month_list %}
<p><a href="">{{ month.0|date:'Y年m月' }}({{ month.1 }})</a></p>
{% endfor %}
</div>
</div>
</div>
{% endblock %}
{% block main %}
<div class="col-md-10">
<div class="article" style="margin-top: 20px">
{% for article in article_list %}
<div>
<h4 class="media-heading"><a href="">{{ article.title }}</a></h4>
<div class="media">
<div class="media-body">
{{ article.desc }}
</div>
<div style="margin-top: 10px" class="pull-right">
<span class="article_footer">posted @</span>
<span class="article_footer">{{ article.create_time|date:'Y-m-d H:i:s' }}</span>
{# <span class="glyphicon glyphicon-thumbs-up article_footer"> {{ article.up_num }}</span>#}
<span class="article_footer"><i
class="fa fa-comment-o fa-lg"></i> {{ article.up_num }}</span>
<span class="article_footer"><i
class="fa fa-home fa-lg"></i> {{ article.down_num }}</span>
<span class='article_footer'><i
class="fa fa-frown-o fa-lg"></i> {{ article.commit_num }}</span>
</div>
</div>
<hr>
</div>
{% endfor %}
</div>
</div>
{% endblock %}
左侧过滤功能
# 查询当前站点下某年某月的文章数(分组依据,日期:年月),不需要连表
from django.db.models.functions import TruncMonth, TruncDay, TruncYear, TruncHour
'''
Sales.objects
.annotate(month=TruncMonth('timestamp')) # Truncate to month and add to select list
.values('month') # Group By month
.annotate(c=Count('id')) # Select the count of the grouping
.values('month', 'c') # (might be redundant, haven't tested) select month and count
'''
month_list = models.Article.objects.filter(blog=user.blog).annotate(month = TruncMonth('create_time')).values('month').annotate(count = Count('id')).values_list('month','count')
id name create_time month
1 xx 2020-09-18:xxx 2020-09
2 xx44 2020-09-18:xxx 2020-09
3 xx44 2020-08-18:xxx 2020-08
'''
按月份阶段分组
'''
# 个人站点
def personal_site(request, username):
user = models.UserInfo.objects.filter(username=username).first()
if user:
article_list = user.blog.article_set.all()
# category_list = user.blog.category_set.all()
# tag_list = user.blog.tag_set.all()
# 查询每个分类下的文章数和分类名称
# category_list = models.Category.objects.values('id').annotate(count=Count('article')).values('count', 'name')
# 查询当前这个站点下的分类及分类下的文章数
category_list = models.Category.objects.filter(blog=user.blog).annotate(count=Count('article')).values('count',
'name')
# 查询当前站点下所有的标签及标签下的文章数
tag_list = models.Tag.objects.filter(blog=user.blog).annotate(count=Count('article')).values_list('count',
'name')
# 查询当前站点下按月分组的文章数和年月
from django.db.models.functions import TruncMonth # 按月截断
month_list = models.Article.objects.filter(blog=user.blog).annotate(month = TruncMonth('create_time')).values('month').annotate(count = Count('id')).values_list('month','count')
return render(request, 'site.html', locals())
else:
return render(request, '404.html')
404.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-1 text-center" style="margin-top: 50px;margin-left: 100px">
<img src="/static/img/404.webp" alt="404图片">
</div>
<div class="col-md-10 col-md-offset-1 text-center" style='margin-top: 20px'>
<button class="btn btn-info btn-block"><a href="/index/">返回首页</a></button>
</div>
</div>
</div>
</body>
</html>
BBS 项目(四)的更多相关文章
- BBS项目分布搭建四(点赞点踩及评论功能准备)
BBS项目分布搭建四(点赞点踩及评论功能) 1. 点赞点踩样式准备 # 在base.html文件中 head标签内 添加css模块: {% block css %} {% endblock %} # ...
- auth复习和BBS项目的登录(1)
auth复习 auth组件 验证:authenticate(request,username='andy',password='123) 登录:login(request,user) 注销:login ...
- BBS项目知识点汇总
目录 bbs项目知识点汇总 一. JavaScript 1 替换头像 2 form表单拿数据 3 form组件error信息渲染 4 添加html代码 5 聚焦操作 二 . html在线编辑器 三 . ...
- 小福bbs—项目系统设计与数据库设计
这个作业属于哪个课程 班级链接 这个作业要求在哪里 作业要求的链接 团队名称 小福bbs 这个作业的目标 实现对校园论坛软件的制作,使其能够发布帖子,查看信息等 作业的正文 小福bbs--项目需求分析 ...
- BBS项目详解(forms快速创建登陆页面,登陆验证、通过阅读器进行头像上传的预览、内存管理器)
BBS项目涉及的知识点 django中知识点 钩子函数(局部钩子和全局钩子) 1.局部钩子就是用来做合法性校验,比如用户名有没有被使用等 2.全局的就是用来做对比校验,比如两次输入的密码是否一致 3. ...
- android 实践项目四
android 实践项目四 本周主要是开发android baidumap实现公交的查询 1.权限的取得和对屏幕的支持 <uses-permission android:name="a ...
- BBS项目部署
1.准备 项目架构为:LNM+Python+Django+uwsgi+Redis (L:linux,N:nginx,M:mysql) 将bbs项目压缩上传到: /opt 在shell中直接拖拽 ...
- python 自动化之路 day 20 Django进阶/BBS项目【一】
一.django进阶 1.django orm 增删改查 1.1.创建表: 1 2 3 >>> from blog.models import Blog >>> b ...
- BBS项目-01
目录 BBS项目 BBS开发流程: BBS表格创建: BBS项目 BBS开发流程: BBS项目: 开发流程: 需求分析 草拟一些项目的大致技术点和流程 架构设计 架构师(框架 语言 数据库 缓存数据库 ...
随机推荐
- Td 内容不换行,超过部分自动截断,用...表示
转载请注明来源:https://www.cnblogs.com/hookjc/ <table width="200px" style="table-layout:f ...
- keystore文件
[-] keystore操作 运行时签名文件路径debug 生成签名文件打包时使用 获取MD5和SH1 修改keystore文件密码 修改keystore文件别名 修改keystore文件别名的密码 ...
- json中传递数组和list
json的数据类型:List,数组,数字,字符串,逻辑值,对象,null 1.如果json传递的是数组,格式: { "name":"网站", "num ...
- springcloud+gateway微服务整合swagger
单一的微服务集成swagger: maven: <dependency> <groupId>io.springfox</groupId> <artifactI ...
- java中将SimpleDateFormat类型转换成Date类型
try {String dateString = "2009-08-02 13:43:00";DateFormat df = SimpleDateFormat("yyyy ...
- python基础语法_闭包详解
https://www.cnblogs.com/Lin-Yi/p/7305364.html 闭包有啥用??!! 很多伙伴很糊涂,闭包有啥用啊??还这么难懂! 3.1装饰器!!!装饰器是做什么的??其 ...
- HMS Core携手厦门大学打造AR增强现实技术
HMS Core AR Engine团队联手厦门大学信息学院,与专业学生面对面深度交流行业发展与前沿成果.双方共同编写行业知识教材,引导学生开发AR游戏实践,为未来AR.VR人才培养培育可复制的教学模 ...
- 我们一起来学Shell - shell的条件判断
文章目录 Shell 条件测试语法 符号说明 Shell 测试表达式 文件测试表达式 字符串测试表达式 整数操作符 逻辑操作符 测试表达式的区别总结 Shell 条件判断之if语句 单分支 IF 条件 ...
- Renix签名字段详解——网络测试仪实操
一.签名字段简介 在添加/修改流量时,会有一个签名字段选项 (1)勾选以后,RENIX软件在发流时,会把每个报文的Payload(净荷)的最后18字节修改为特殊的值,用来统计流的时延.丢包等内容 (2 ...
- 从数据分析系统总架构理解BI工具的价值所在
现如今,应用商业智能BI工具的企业是越来越多了,由此也可见企业对数据分析的重视.因此,掌握一定的数据分析知识对"打工人"来说是非常重要的.现在小编就来跟大家一起来了解一下商业智能 ...