管理信息系统 课程设计

 

1、项目选择php

  1. 继续沿用Python+Flask+MysqL的web建设技术,开发一个网站
  2. 网站主题根据我的兴趣与特长自由选择
  3. 此项目属于我的项目,每一个同窗独立完成,和其余同窗不同 

2、项目要求css

    1. 整个网站风格统一,布局合理,尽可能美观。
    2. 做品必须完成:
      1. 网站父模板统一布局:头部导航条、底部图片导航、中间主显示区域布局
      2. 注册、登陆、注销
      3. 发布、列表显示
      4. 详情页
      5. 评论、列表显示
      6. 我的中心
      7. 搜索,条件组合搜索
      8. 文章分类、显示
      9. 点赞、收藏
      10. 修改密码、头像、上传头像
      11. 个人发布、点赞、收藏、评论
      12. 高级搜索
      13. 热门文章、推荐文章
    3.  参考网站:http://bbs.xiaomi.cn/

A.系统概要说明html

这个网站我作的是有关文学论坛的系统,基于Python+Flask+MysqL的web建设技术,在上学期学习的基础上进行完善,虽然不算完美,可是对Python有了更进一步的了解,作起来更驾轻就熟。前端

Python优势:python

1.“优雅”、“明确”、“简单”web

      这是python的定位,使得python程序看上去简单易懂,初学者容易入门,学习成本更低。但随着学习的不但深刻,python同样能够知足胜任复杂场景的开发需求。引用一个说法,Python的哲学是就是简单优雅,尽可能写容易看明白的代码,尽可能写少的代码。算法

2.  开发效率高sql

     python做为一种高级语言,具备丰富的第三方库,官方库中也有相应的功能模块支持,覆盖了网络、文件、GUI、数据库、文本等大量内容。所以开发者无需事必躬亲,遇到主流的功能需求时能够直接调用,在基础库的基础上施展拳脚,能够节省你不少功力和时间成本,大大下降开发周期。shell

3.  无需关注底层细节数据库

     Python做为一种高级开发语言,在编程时无需关注底层细节(如内存管理等)。

4.  功能强大

     Python是一种前端后端通吃的综合性语言,功能强大,php能胜任的角色它都能作,至于后端如何胜任,须要在后续学习中逐步领悟。

5.  可移植性

     Python能够在多种主流的平台上运行,开发程序时只要绕开对系统平台的依赖性,则能够在无需修改的前提下运行在多种系统平台上,具体有待后续学习中深刻展开。其余优势有待继续发掘。

  Python缺点:

1. 代码运行速度慢

    由于Python是一种高级开发语言,不像c语言同样能够深刻底层硬件最大程度上挖掘榨取硬件的性能,所以它的运行速度要远远慢于c语言。另一个缘由是,Python是解释型语言,你的代码在执行时会一行一行地翻译成CPU能理解的机器码,这个翻译过程很是耗时,因此很慢。而C程序是运行前直接编译成CPU能执行的机器码,因此很是快。

    但须要注意的是,这种慢对于不须要追求硬件高性能的应用场合来说根本不是问题,由于它们比较的数量级根本不是用户能直观感觉到的!想一想程序执行所需的时间数量级?例如开发一个下载MP3的网络应用程序,C程序的运行时间须要0.001秒,而Python程序的运行时间须要0.1秒,慢了100倍,但因为网络更慢,须要等待1秒,用户体验几乎没有差异,除非你用很是精确的计时器来计时。

2.  发布程序时必须公开源代码

     什么?有没有搞错?是的,发布程序时咱们必须公开源代码!仍是由于Python是一种解释性语言,没有编译打包的过程(听说最新的python能够打包,但本质上仍是把源代码和解释器打在一块儿,没有太大实际意义)。想一想咱们的shell脚本是否是也是这个状况,你能在不发布源代码的状况下发布一个黑盒子程序来让别人正常使用么?

     这个缺点仅限于你想单纯靠卖开发出来的软件产品挣钱的时候。但在这个开发互联的时代,不靠卖产品自己来赚钱的商业模式愈来愈主流了,因此问题也不是无法解决。 

B.网站结构设计

网站的结构设计是体现内容设计与创意设计的关键环节,在内容设计完成以后,网站的目标及内容主题等有关问题已经肯定。结构设计要作的事情就是如何将内容划分为清晰合理的层次体系,好比栏目的划分及其关系、网页的层次及其关系、连接的路径设置、功能在网页上的分配等等,以上这些都仅仅是前台结构设计,而前台结构设计的实现须要强大的后台支撑,后台也应有良好的结构设计以保证前台结构设计的实现。在我看来,根据开发量来讲,Flask小巧简单易上手,同时具备强大的扩展能力,使其功能能够不弱于django、Tornado等框架,我最终选择了Flask。从 建表设计 到  浏览器前端展现 总体的结构,后台链接数据库,总体布局是否美观,都是从网站结构分析这方面出发要考虑的问题.

C.模块详细设计

模块详细设计这一方面,我是从

  1. 网站父模板统一布局:头部导航条、底部图片导航、中间主显示区域布局
  2. 注册、登陆、注销
  3. 发布、列表显示
  4. 详情页
  5. 评论、列表显示
  6. 我的中心
  7. 搜索,条件组合搜索
  8. 文章分类、显示
  9. 点赞、收藏
  10. 修改密码、头像、上传头像
  11. 个人发布、点赞、收藏、评论
  12. 高级搜索
  13. 热门文章、推荐文章

这几方面来规划个人整个网站的,以及考虑实现功能所需的类及具体的方法函数,包括涉及到的sql语句、Python+Flask+MysqL的web建设技术等。

D.数据库设计

一直以来,在数据库库方面我掌握的不是很好,有些细节的东西我会不当心忽略。但在这一次大做业设计中,感受本身能力有所提升,对数据库也有了更进一步的掌握。

数据库设计的设计内容包括:需求分析、概念结构设计、逻辑结构设计、物理结构设计、数据库的实施和数据库的运行和维护。

数据库设计是指对于一个给定的应用环境,构造最优的数据库模式,创建数据库及其应用系统,使之可以有效地存储数据,知足各类用户的应用需求(信息要求和处理要求)。在数据库领域内,经常把使用数据库的各种系通通称为数据库应用系统

咱们要搭建后台,与MySQL相链接,多是因为我电脑的问题,MySQL常常自动关闭,这个时候要打开电脑的管理,去服务那里设置为自动。有时候百度能解决不少问题。

链接数据库前,要先确认如下事项:

  • 已经建立了数据库 TESTDB.
  • 在TESTDB数据库中您已经建立了表 EMPLOYEE
  • EMPLOYEE表字段为 FIRST_NAME, LAST_NAME, AGE, SEX 和 INCOME。
  • 链接数据库TESTDB使用的用户名为 "testuser" ,密码为 "test123",你能够能够本身设定或者直接使用root用户名及其密码,Mysql数据库用户受权请使用Grant命令。
  • 在你的机子上已经安装了 Python MySQLdb 模块。

再者,数据库要明确步骤,需求分析、概念设计、逻辑设计、物理设计、验证设计和运行维护设计,这些都缺一不可。

from flask import Flask
from exts import db #数据库使用方法
import config #数据库链接文件
from apps.front import bp as front_bp #链接前端数据文件

E.系统实现的关键算法与数据结构

def create_app():
app = Flask(__name__)
app.config.from_object(config)
app.register_blueprint(front_bp)
db.init_app(app)

return app


if __name__ == '__main__':
app = create_app()
app.run(port=8000)
#点赞功能
@bp.route('/dianzan/',methods=['GET','POST'])
@login_required
def dianzan():
user_id=g.front_user.id
post_id=request.form.get('post_id')
dianzan=DianzanModel(user_id=user_id,post_id=post_id)
db.session.add(dianzan)
db.session.commit()
return redirect(url_for('front.post_detail',post_id=post_id))

#用户上传头像
@bp.route('/avatar/<user_id>',methods=['POST'])
@login_required
def updata_acatar(user_id):
user = FrontUser.query.filter(FrontUser.id == user_id).first()
f = request.files['img']
basepath = os.path.dirname(__file__) # 当前文件所在路径
upload_path = os.path.join('F:/godlike/static/img', f.filename) # 注意:没有的文件夹必定要先建立,否则会提示没有该路径
f.save(upload_path)
user.avatar = 'img/' + f.filename
db.session.commit()
return redirect(url_for('front.usercenter',user_id=user.id,tag=1))

 F.主要代码:

#搜索功能
@bp.route('/search/')
def search():
qu = request.args.get('q')
ques = PostModel.query.filter(
and_(
PostModel.title.contains(qu)
)
).order_by('-create_time')
board_id = request.args.get('bd', type=int, default=None)
page = request.args.get(get_page_parameter(), type=int, default=1)
boards = BoardModel.query.all()
start = (page - 1) * config.PER_PAGE
end = start + config.PER_PAGE
total = 0

query_obj = PostModel.query.order_by(PostModel.create_time.desc())
if board_id:
query_obj = query_obj.filter_by(board_id=board_id)
posts = query_obj.slice(start, end)
total = query_obj.count()
else:
posts = query_obj.slice(start, end)
total = query_obj.count()
pagination = Pagination(bs_version=3, page=page, total=total, outer_window=0, inner_window=2)
context = {
'boards': boards,
'posts': ques,
'pagination': pagination,
'current_board': board_id

}

return render_template('front/front_index.html',**context)


#我的中心
@bp.route('/usercenter/<user_id>/<tag>')
@login_required
def usercenter(user_id,tag):
user = FrontUser.query.filter(FrontUser.id==user_id).first()
posts = PostModel.query.filter(PostModel.author_id == user_id).all()
context = {
'user':user,
'posts':posts
}
if tag == '1':
return render_template('front/front_usercenter.html',**context)
if tag == '2':
return render_template('front/front_user_apost.html',**context)

#点赞功能
@bp.route('/dianzan/',methods=['GET','POST'])
@login_required
def dianzan():
user_id=g.front_user.id
post_id=request.form.get('post_id')
dianzan=DianzanModel(user_id=user_id,post_id=post_id)
db.session.add(dianzan)
db.session.commit()
return redirect(url_for('front.post_detail',post_id=post_id))

#用户上传头像
@bp.route('/avatar/<user_id>',methods=['POST'])
@login_required
def updata_acatar(user_id):
user = FrontUser.query.filter(FrontUser.id == user_id).first()
f = request.files['img']
basepath = os.path.dirname(__file__) # 当前文件所在路径
upload_path = os.path.join('F:/godlike/static/img', f.filename) # 注意:没有的文件夹必定要先建立,否则会提示没有该路径
f.save(upload_path)
user.avatar = 'img/' + f.filename
db.session.commit()
return redirect(url_for('front.usercenter',user_id=user.id,tag=1))


#用户修改我的信息
@bp.route('/user_updata/<user_id>',methods=['GET','POST'])
@login_required
def user_updata(user_id):
if request.method == 'GET':
user= FrontUser.query.filter(FrontUser.id==user_id).first()
return render_template('front/front_user_updata.html',user=user)
else:
form = UserupdataForm(request.form)
if form.validate():
username = form.username.data
realname = form.realname.data
signature = request.form.get('signature')
user = g.front_user
user.username =username
user.realname = realname
user.signature = signature
db.session.commit()
return restful.success()
else:
return restful.params_error(form.get_error())


#用户修改密码
@bp.route('/resetpwd/',methods=['GET','POST'])
@login_required
def resetpwd():
if request.method == 'GET':
return render_template('front/front_resetpwd.html')
else:
form = ResetpwdForm(request.form)
if form.validate():
oldpwd = form.oldpwd.data
newpwd = form.newpwd.data
user = g.front_user
if user.check_password(oldpwd):
user.password = newpwd
db.session.commit()
# {"code":200,message=""}
# return jsonify({"code":200,"message":""})
return restful.success()
else:
return restful.params_error("旧密码错误!")
else:
return restful.params_error(form.get_error())

#注销
@bp.route('/logout/')
@login_required
def logout():
del session[config.FRONT_USER_ID]
return redirect(url_for('front.index'))
#注册功能后台视图
class SignupView(views.MethodView):
def get(self):
return_to = request.referrer
if return_to and return_to != request.url and safeutils.is_safe_url(return_to):
return render_template('front/front_signup.html',return_to=return_to)
else:
return render_template('front/front_signup.html')
def post(self):
form = SignupForm(request.form)
if form.validate():
email = form.email.data
username = form.username.data
password = form.password1.data
user = FrontUser(email=email,username=username,password=password)
db.session.add(user)
db.session.commit()
return restful.success()
else:
print(form.get_error())
return restful.params_error(message=form.get_error())
#登陆功能后台视图
class SigninView(views.MethodView):
def get(self):
return_to = request.referrer
if return_to and return_to != request.url and return_to != url_for("front.signup") and safeutils.is_safe_url(
return_to):
return render_template('front/front_signin.html', return_to=return_to)
else:
return render_template('front/front_signin.html')
def post(self):
form =SigninForm(request.form)
if form.validate():
email = form.email.data
password = form.password.data
remember = form.remeber.data
user = FrontUser.query.filter_by(email=email).first()
if user and user.check_password(password):
session[config.FRONT_USER_ID]=user.id
if remember:
session.permanent= True
return restful.success()
else:
return restful.params_error(message='邮箱或密码错误!')
else:
return restful.params_error(message=form.get_error())

首页代码:
{% from "common/_macros.html" import static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
{% include "common/_heads.html" %}
<link rel="stylesheet" href="{{ static('front/css/front_base.css') }}">
<title>
{% block title %}{% endblock %}
</title>
{% block head %}{% endblock %}
</head>
<body>
<div class="banner">

<ul style="">
<li class="first"><a href="{{ url_for("front.index") }}">论坛首页</a></li>
<li class="first"><a href="{{ url_for("front.index") }}">全部文章</a></li>
<li class="first"><a href="">热门精选</a></li>
<li class="first"><a href="{{ url_for("front.apost") }}">发布帖子</a></li>
{# <!--<li class="first"><a href=""></a></li>-->#}
</ul>

<div class="banner_search">
<form action="{{ url_for('front.search') }}" method="get">
<input type="text" name="q" id="" value="" placeholder="请输入关键字"/>
<button type="submit">搜索</button>
</form>
</div>
<div class="banner_right">
{% if g.front_user %}
<span id="login-tag" data-is-login="1" style="display: none;"></span>
<a href="{{ url_for('front.usercenter',user_id=g.front_user.id,tag="1") }}">{{ g.front_user.username }}</a>
<span>or</span>
<a href="{{ url_for('front.logout') }}">注销</a>
{% else %}
<a href="{{ url_for('front.signin') }}">登陆</a>
<span>or</span>
<a href="{{ url_for("front.signup") }}">注册</a>
{% endif %}
</div>
</div>


<div class="main-container">
{% block body %}{% endblock %}
</div>

</body>
</html>
帖子加精:
{% from "common/_macros.html" import static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>帖子加精</title>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
{% include "common/_heads.html" %}
<script src="{{ static("front/js/jiajing.js") }}"></script>
</head>
<body>
<div style="width: 1000px; margin: 50px auto; ">
<table class="table table-bordered" style="text-align: center">
<thead>
<tr>
<th>帖子标题</th>
<th>做者</th>
<th>发布时间</th>
<th>所属板块</th>
<th>操做</th>
</tr>
</thead>
{% for foo in post %}
<tr data-id="{{ foo.id }}" data-highlight="{{ 1 if foo.highlight else 0}}">

<th><a target="_blank" href="{{ url_for("front.post_detail",post_id=foo.id) }}">{{ foo.title }}</a></th>
<th>{{ foo.author.username }}</th>
<th>{{ foo.board.name }}</th>
<th>{{ foo.create_time }}</th>
<th>
{% if foo.highlight %}
<button type="button" class="btn btn-default highlight-btn">取消加精</button>
{% else%}
<button type="button" class="btn btn-danger highlight-btn">加精</button>
{% endif %}

</th>



</tr>
{% endfor %}
</table>
</div>
</body>
</html>

G.成品展现

论坛首页:

注册页面:

 

格式不标准时:

 

登陆界面:

登陆成功:

 

发布帖子:

发布成功:

若是要设置帖子等级,须要数据库后台改id:

 

点赞和评论功能:

 

 

我的中心:

 

 修改密码:

 

 

密码不一致时:

 

搜索帖子:

 

 

 我的总结:在本学期的课程设计当中,尽管是基于上学期的知识上的改进,但仍是有点不完美的。在一开始要搭建各类虚拟环境,虽然有视频教学,但大部分仍是要靠本身去领悟理解。如何让页面布局更加美观,完善具体功能,如何熟练运用Python+Flask+MysqL的web建设技术,都是要靠本身去摸索领悟的。不要惧怕代码报错,一步步解决才能学到更多。