项目介绍
随着计算机技术发展,计算机系统的应用已延伸到社会的各个领域,大量基于大数据的广泛应用给生活带来了十分的便利。博客系统凭借其开放性、持久性和深度内容,为个体提供了独特的自我展示和交流空间。此外,博客系统互操作性和自定义功能,为用户提供了高度的自主性和个性化体验,这在数字时代对维护信息多样性和促进民主参与具有重要意义。
系统阐述的是博客系统的设计与实现,对于Python、B/S结构、MySQL进行了较为深入的学习与应用。主要针对系统的设计,描述,实现和分析与测试方面来表明开发的过程。开发中使用了Flask框架和MySQL数据库技术搭建系统的整体架构。利用这些技术结合实际需求开发了具有用户管理,标签管理,分类管理,文章管理,公告资讯管理,举报信息管理,消息通知管理,系统管理,我的信息等功能的系统,最后对系统进行相应的测试,测试系统有无存在问题以及测试用户权限来优化系统,最后系统达到预期目标。
开发环境
编程语言:Python
数据库 :Mysql
系统架构:B/S
前端技术:Vue
编译工具:pycharm
支持定做:java/php/python/android/小程序vue/爬虫/c#/asp.net
系统截图
核心代码
import logging, os, json, configparser
import time
from datetime import datetime
from flask import request, jsonify,session
from sqlalchemy.sql import func,and_,or_,case
from sqlalchemy import cast, Integer,Float
from api.models.brush_model import *
from . import main_bp
from utils.codes import *
from utils.jwt_auth import Auth
from configs import configs
from utils.helper import *
import random
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
from email.header import Header
from utils.baidubce_api import BaiDuBce
from api.models.config_model import config
# 注册接口
@main_bp.route("/python12j5u0rf/fenlei/register", methods=['POST'])
def python12j5u0rf_fenlei_register():
if request.method == 'POST':
msg = {'code': normal_code, 'message': 'success', 'data': [{}]}
req_dict = session.get("req_dict")
if req_dict.get('mima') != None:
req_dict['mima'] = computeMD5(req_dict['mima'])
error = fenlei.createbyreq(fenlei, fenlei, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = "注册用户已存在"
return jsonify(msg)
# 登录接口
@main_bp.route("/python12j5u0rf/fenlei/login", methods=['GET','POST'])
def python12j5u0rf_fenlei_login():
if request.method == 'GET' or request.method == 'POST':
msg = {"code": normal_code, "msg": "success", "data": {}}
req_dict = session.get("req_dict")
req_model = session.get("req_dict")
try:
del req_model['role']
except:
pass
req_model['password'] = computeMD5(req_model['password'])
datas = fenlei.getbyparams(fenlei, fenlei, req_model)
if not datas:
msg['code'] = password_error_code
msg['msg']='密码错误或用户不存在'
return jsonify(msg)
req_dict['id'] = datas[0].get('id')
try:
del req_dict['mima']
except:
pass
return Auth.authenticate(Auth, fenlei, req_dict)
# 登出接口
@main_bp.route("/python12j5u0rf/fenlei/logout", methods=['POST'])
def python12j5u0rf_fenlei_logout():
if request.method == 'POST':
msg = {
"msg": "退出成功",
"code": 0
}
req_dict = session.get("req_dict")
return jsonify(msg)
# 重置密码接口
@main_bp.route("/python12j5u0rf/fenlei/resetPass", methods=['POST'])
def python12j5u0rf_fenlei_resetpass():
'''
'''
if request.method == 'POST':
msg = {"code": normal_code, "msg": "success"}
req_dict = session.get("req_dict")
if req_dict.get('mima') != None:
req_dict['mima'] = computeMD5('123456')
error = fenlei.updatebyparams(fenlei, fenlei, req_dict)
if error != None:
msg['code'] = crud_error_code
msg['msg'] = error
else:
msg['msg'] = '密码已重置为:123456'
return jsonify(msg)
# 获取会话信息接口
@main_bp.route("/python12j5u0rf/fenlei/session", methods=['GET'])
def python12j5u0rf_fenlei_session():
'''
'''
if request.method == 'GET':
msg = {"code": normal_code, "data": {}}
req_dict={"id":session.get('params').get("id")}
msg['data'] = fenlei.getbyparams(fenlei, fenlei, req_dict)[0]
return jsonify(msg)
# 分类接口(后端)
@main_bp.route("/python12j5u0rf/fenlei/page", methods=['GET'])
def python12j5u0rf_fenlei_page():
'''
'''
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = session.get("req_dict")
userinfo = session.get("params")
try:
__hasMessage__=fenlei.__hasMessage__
except:
__hasMessage__=None
if __hasMessage__ and __hasMessage__!="否":
tablename=session.get("tablename")
if tablename!="users" and session.get("params")!=None and fenlei!='chat':
req_dict["userid"]=session.get("params").get("id")
tablename=session.get("tablename")
if tablename=="users" :
try:
pass
except:
pass
else:
mapping_str_to_object = {}
for model in Base_model._decl_class_registry.values():
if hasattr(model, '__tablename__'):
mapping_str_to_object[model.__tablename__] = model
try:
__isAdmin__=mapping_str_to_object[tablename].__isAdmin__
except:
__isAdmin__=None
if __isAdmin__!="是" and session.get("params")!=None:
req_dict["userid"]=session.get("params").get("id")
else:
try:
del req_dict["userid"]
except:
pass
clause_args = []
or_clauses = or_(*clause_args)
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = fenlei.page(fenlei, fenlei, req_dict, or_clauses)
return jsonify(msg)
# 排序接口
@main_bp.route("/python12j5u0rf/fenlei/autoSort", methods=['GET'])
def python12j5u0rf_fenlei_autosort():
'''
'''
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = session.get("req_dict")
req_dict['sort']='clicktime'
req_dict['order']='desc'
try:
__browseClick__= fenlei.__browseClick__
except:
__browseClick__=None
if __browseClick__ =='是':
req_dict['sort']='clicknum'
elif __browseClick__ =='时长':
req_dict['sort']='browseduration'
else:
req_dict['sort']='clicktime'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = fenlei.page(fenlei, fenlei, req_dict)
return jsonify(msg)
# 分页接口(前端)
@main_bp.route("/python12j5u0rf/fenlei/list", methods=['GET'])
def python12j5u0rf_fenlei_list():
'''
'''
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = session.get("req_dict")
if req_dict.__contains__('vipread'):
del req_dict['vipread']
userinfo = session.get("params")
try:
__foreEndList__=fenlei.__foreEndList__
except:
__foreEndList__=None
if __foreEndList__ and __foreEndList__!="否":
tablename=session.get("tablename")
if tablename!="users" and session.get("params")!=None:
req_dict['userid']=session.get("params").get("id")
try:
__foreEndListAuth__=fenlei.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="否":
tablename=session.get("tablename")
if tablename!="users" and session.get("params")!=None:
req_dict['userid']=session.get("params").get("id")
tablename=session.get("tablename")
if tablename=="users" :
try:
del req_dict["userid"]
except:
pass
else:
mapping_str_to_object = {}
for model in Base_model._decl_class_registry.values():
if hasattr(model, '__tablename__'):
mapping_str_to_object[model.__tablename__] = model
try:
__isAdmin__=mapping_str_to_object[tablename].__isAdmin__
except:
__isAdmin__=None
if __isAdmin__!="是" and session.get("params")!=None:
req_dict["userid"]=session.get("params").get("id")
if 'luntan' in 'fenlei':
if 'userid' in req_dict.keys():
del req_dict["userid"]
if 'discuss' in 'fenlei':
if 'userid' in req_dict.keys():
del req_dict["userid"]
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = fenlei.page(fenlei, fenlei, req_dict)
return jsonify(msg)
# 保存接口(后端)
@main_bp.route("/python12j5u0rf/fenlei/save", methods=['POST'])
def python12j5u0rf_fenlei_save():
'''
'''
request.operation = "新增分类"
if request.method == 'POST':
msg = {"code": normal_code, "msg": "success", "data": {}}
req_dict = session.get("req_dict")
if fenlei.count(fenlei, fenlei, {"fenlei":req_dict["fenlei"]})>0:
msg['code'] = crud_error_code
msg['msg'] = "分类已存在"
return jsonify(msg)
for key in req_dict:
if req_dict[key] == '':
req_dict[key] = None
error= fenlei.createbyreq(fenlei, fenlei, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return jsonify(msg)
# 添加接口(前端)
@main_bp.route("/python12j5u0rf/fenlei/add", methods=['POST'])
def python12j5u0rf_fenlei_add():
'''
'''
request.operation = "新增分类"
if request.method == 'POST':
msg = {"code": normal_code, "msg": "success", "data": {}}
req_dict = session.get("req_dict")
if fenlei.count(fenlei, fenlei, {"fenlei":req_dict["fenlei"]})>0:
msg['code'] = crud_error_code
msg['msg'] = "分类已存在"
return jsonify(msg)
try:
__foreEndListAuth__=fenlei.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="否":
tablename=session.get("tablename")
if tablename!="users":
req_dict['userid']=session.get("params").get("id")
error= fenlei.createbyreq(fenlei, fenlei, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return jsonify(msg)
# 踩、赞接口
@main_bp.route("/python12j5u0rf/fenlei/thumbsup/<id_>", methods=['GET'])
def python12j5u0rf_fenlei_thumbsup(id_):
'''
'''
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data": {}}
req_dict = session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=fenlei.getbyid(fenlei, fenlei,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = fenlei.updatebyparams(fenlei, fenlei, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return jsonify(msg)
# 获取详情信息(后端)
@main_bp.route("/python12j5u0rf/fenlei/info/<id_>", methods=['GET'])
def python12j5u0rf_fenlei_info(id_):
'''
'''
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data": {}}
data = fenlei.getbyid(fenlei, fenlei, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= fenlei.__browseClick__
except:
__browseClick__=None
if __browseClick__ and "clicknum" in fenlei.__table__.columns:
click_dict={"id":int(id_),"clicknum":str(int(data[0].get("clicknum") or 0)+1)}
ret=fenlei.updatebyparams(fenlei,fenlei,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return jsonify(msg)
# 获取详情信息(前端)
@main_bp.route("/python12j5u0rf/fenlei/detail/<id_>", methods=['GET'])
def python12j5u0rf_fenlei_detail(id_):
'''
'''
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data": {}}
data = fenlei.getbyid(fenlei, fenlei, int(id_))
if len(data)>0:
msg['data']=data[0]
#浏览点击次数
try:
__browseClick__= fenlei.__browseClick__
except:
__browseClick__=None
if __browseClick__ and "clicknum" in fenlei.__table__.columns:
click_dict={"id":int(id_),"clicknum":str(int(data[0].get("clicknum") or 0)+1)}
ret=fenlei.updatebyparams(fenlei,fenlei,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return jsonify(msg)
# 更新接口
@main_bp.route("/python12j5u0rf/fenlei/update", methods=['POST'])
def python12j5u0rf_fenlei_update():
'''
'''
request.operation = "更新分类"
if request.method == 'POST':
msg = {"code": normal_code, "msg": "success", "data": {}}
req_dict = session.get("req_dict")
if db.session.query(func.count(getattr(fenlei, 'id'))).filter(fenlei.id !=req_dict["id"], fenlei.fenlei == req_dict["fenlei"]).scalar()>0:
msg['code'] = crud_error_code
msg['msg'] = "分类已存在"
return jsonify(msg)
if req_dict.get("mima") and "mima" not in fenlei.__table__.columns :
del req_dict["mima"]
if req_dict.get("password") and "password" not in fenlei.__table__.columns :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = fenlei.updatebyparams(fenlei, fenlei, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return jsonify(msg)
# 删除接口
@main_bp.route("/python12j5u0rf/fenlei/delete", methods=['POST'])
def python12j5u0rf_fenlei_delete():
'''
'''
request.operation = "删除分类"
if request.method == 'POST':
msg = {"code": normal_code, "msg": "success", "data": {}}
req_dict = session.get("req_dict")
error=fenlei.delete(
fenlei,
req_dict
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return jsonify(msg)
# 投票接口
@main_bp.route("/python12j5u0rf/fenlei/vote/<int:id_>", methods=['POST'])
def python12j5u0rf_fenlei_vote(id_):
'''
'''
if request.method == 'POST':
msg = {"code": normal_code, "msg": "success"}
data= fenlei.getbyid(fenlei, fenlei, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=fenlei.updatebyparams(fenlei,fenlei,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return jsonify(msg)
# 分组统计接口
@main_bp.route("/python12j5u0rf/fenlei/group/<columnName>", methods=['GET'])
def python12j5u0rf_fenlei_group(columnName):
'''
分组统计接口
'''
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data": {}}
req_dict = session.get("req_dict")
userinfo = session.get("params")
msg['data'] = fenlei.groupbycolumnname(fenlei,fenlei,columnName,req_dict)
msg['data'] = msg['data'][:10]
json_filename='fenlei'+f'_group_{columnName}.json'
where = ' where 1 = 1 '
sql = "SELECT COUNT(*) AS total, " + columnName + " FROM fenlei " + where + " GROUP BY " + columnName
return jsonify(msg)
# 按值统计接口
@main_bp.route("/python12j5u0rf/fenlei/value/<xColumnName>/<yColumnName>", methods=['GET'])
def python12j5u0rf_fenlei_value(xColumnName, yColumnName):
'''
按值统计接口,
{
"code": 0,
"data": [
{
"total": 10.0,
"shangpinleibie": "aa"
},
{
"total": 20.0,
"shangpinleibie": "bb"
},
{
"total": 15.0,
"shangpinleibie": "cc"
}
]
}
'''
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data": {}}
req_dict = session.get("req_dict")
userinfo = session.get("params")
msg['data'] = fenlei.getvaluebyxycolumnname(fenlei,fenlei,xColumnName,yColumnName,req_dict)
msg['data'] = msg['data'][:10]
return jsonify(msg)
# 按日期统计接口
@main_bp.route("/python12j5u0rf/fenlei/value/<xColumnName>/<yColumnName>/<timeStatType>", methods=['GET'])
def python12j5u0rf_fenlei_value_riqi(xColumnName, yColumnName, timeStatType):
'''
按日期统计接口
'''
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data": {}}
userinfo = session.get("params")
where = ' where 1 = 1 '
sql = ''
if timeStatType == '日':
sql = "SELECT DATE_FORMAT({0}, '%Y-%m-%d') {0}, sum({1}) total FROM fenlei {2} GROUP BY DATE_FORMAT({0}, '%Y-%m-%d')".format(xColumnName, yColumnName, where, '%Y-%m-%d')
if timeStatType == '月':
sql = "SELECT DATE_FORMAT({0}, '%Y-%m') {0}, sum({1}) total FROM fenlei {2} GROUP BY DATE_FORMAT({0}, '%Y-%m')".format(xColumnName, yColumnName, where, '%Y-%m')
if timeStatType == '年':
sql = "SELECT DATE_FORMAT({0}, '%Y') {0}, sum({1}) total FROM fenlei {2} GROUP BY DATE_FORMAT({0}, '%Y')".format(xColumnName, yColumnName, where, '%Y')
data = db.session.execute(sql)
data = data.fetchall()
results = []
for i in range(len(data)):
result = {
xColumnName: decimalEncoder(data[i][0]),
'total': decimalEncoder(data[i][1])
}
results.append(result)
msg['data'] = results
json_filename='fenlei'+f'_value_{xColumnName}_{yColumnName}.json'
return jsonify(msg)
# 按值统计(多)
@main_bp.route("/python12j5u0rf/fenlei/valueMul/<xColumnName>", methods=['GET'])
def python12j5u0rf_fenlei_valueMul(xColumnName):
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data": []}
req_dict = session.get("req_dict")
userinfo = session.get("params")
where = ' where 1 = 1 '
for item in req_dict['yColumnNameMul'].split(','):
sql = "SELECT {0}, sum({1}) AS total FROM fenlei {2} GROUP BY {0} LIMIT 10".format(xColumnName, item, where)
L = []
data = db.session.execute(sql)
data = data.fetchall()
for i in range(len(data)):
result = {
xColumnName: decimalEncoder(data[i][0]),
'total': decimalEncoder(data[i][1])
}
L.append(result)
msg['data'].append(L)
return jsonify(msg)
# 按值统计(多)
@main_bp.route("/python12j5u0rf/fenlei/valueMul/<xColumnName>/<timeStatType>", methods=['GET'])
def python12j5u0rf_fenlei_valueMul_time(xColumnName):
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data": []}
req_dict = session.get("req_dict")
userinfo = session.get("params")
timeStatType = req_dict['timeStatType']
where = ' where 1 = 1 '
for item in req_dict['yColumnNameMul'].split(','):
sql = ''
if timeStatType == '日':
sql = "SELECT DATE_FORMAT({0}, '%Y-%m-%d') {0}, sum({1}) total FROM fenlei {2} GROUP BY DATE_FORMAT({0}, '%Y-%m-%d') LIMIT 10".format(xColumnName, item, where, '%Y-%m-%d')
if timeStatType == '月':
sql = "SELECT DATE_FORMAT({0}, '%Y-%m') {0}, sum({1}) total FROM fenlei {2} GROUP BY DATE_FORMAT({0}, '%Y-%m') LIMIT 10".format(xColumnName, item, where, '%Y-%m')
if timeStatType == '年':
sql = "SELECT DATE_FORMAT({0}, '%Y') {0}, sum({1}) total FROM fenlei {2} GROUP BY DATE_FORMAT({0}, '%Y') LIMIT 10".format(xColumnName, item, where, '%Y')
L = []
data = db.session.execute(sql)
data = data.fetchall()
for i in range(len(data)):
result = {
xColumnName: decimalEncoder(data[i][0]),
'total': decimalEncoder(data[i][1])
}
L.append(result)
msg['data'].append(L)
return jsonify(msg)
# 统计接口
@main_bp.route("/python12j5u0rf/fenlei/remind/<columnName>/<type>", methods=['GET']) #
def python12j5u0rf_fenlei_remind(columnName,type):
'''
'''
if request.method == 'GET':
msg = {"code": normal_code, 'count': 0}
# 组合查询参数
params = session.get("req_dict")
remindstart = 0
remindend =9999990
if int(type)==1:#数字
if params.get('remindstart') == None and params.get('remindend') != None:
remindstart = 0
remindend = int(params['remindend'])
elif params.get('remindstart') != None and params.get('remindend') == None:
remindstart = int(params['remindstart'])
remindend = 999999
elif params.get('remindstart') == None and params.get('remindend') == None:
remindstart = 0
remindend = 999999
else:
remindstart = params.get('remindstart')
remindend = params.get('remindend')
elif int(type)==2:#日期
current_time=int(time.time())
if params.get('remindstart') == None and params.get('remindend') != None:
starttime=current_time-60*60*24*365*2
params['remindstart'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(starttime))
endtime=current_time+60*60*24*params.get('remindend')
params['remindend'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(endtime))
elif params.get('remindstart') != None and params.get('remindend') == None:
starttime= current_time - 60 * 60 * 24 * params.get('remindstart')
params['remindstart']=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(starttime))
endtime=current_time+60*60*24*365*2
params['remindend'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(endtime))
elif params.get('remindstart') == None and params.get('remindend') == None:
starttime = current_time - 60 * 60 * 24 * 365 * 2
params['remindstart'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(starttime))
endtime = current_time + 60 * 60 * 24 * 365 * 2
params['remindend'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(endtime))
data = fenlei.getbetweenparams(
fenlei,
fenlei,
columnName,
{
"remindStart": remindstart,
"remindEnd": remindend
}
)
msg['count'] = len(data)
return jsonify(msg)
#分类列表
@main_bp.route("/python12j5u0rf/fenlei/lists", methods=['GET'])
def python12j5u0rf_fenlei_lists():
if request.method == 'GET':
msg = {"code": normal_code, "msg": "success", "data": []}
list,_,_,_,_ = fenlei.page(fenlei,fenlei,{})
msg['data'] = list
return jsonify(msg)
论文参考
目 录
1 绪 论 1
1.1 选题背景与意义 1
1.2 国内外研究现状 1
1.3 研究内容 2
2 关键技术介绍 3
2.1 PYTHON语言简介 3
2.2 MySQL数据库 3
2.3 FLASK框架 4
2.4 Vue框架 5
2.5 B/S架构 5
3 系统分析 7
3.1功能需求分析 7
3.2系统可行性分析 7
3.2.1技术可行性 7
3.2.2 经济可行性 8
3.2.3社会可行性 8
3.3 系统功能分析 8
3.4系统流程分析 9
3.4.1 登录流程图 10
3.4.2 添加新用户流程图 10
第四章 系统设计 12
4.1系统设计原理 12
4.2功能模块设计 12
4.3 数据库设计 12
4.3.1数据库设计原则 12
4.3.2数据库E-R图设计 13
4.3.3数据库表结构设计 13
5 系统的实现 22
5.1系统功能实现 22
5.2管理员功能实现 24
6系统测试 32
6.1系统测试的目的 32
6.2软件测试过程 32
6.3系统测试用例 33
结 论 34
致 谢 35
参考文献 36