管理信息系統 課程設計
1 系統概要說明
眾所周知,當今社會信息科技日新月異,各種需要的、不需要的信息充斥網絡各個角落。當網絡用戶對某種信息產生需求時,特定主題的網絡論壇則是很好的信息來源。
論壇如同雨後春筍般的出現,並迅速的發展壯大。現在的論壇幾乎涵蓋了我們生活的各個方面,幾乎每一個人都可以找到自己感興趣或者需要了解的論壇。但綜合類的論壇由於廣便難於精,於是專題性的論壇繼而出現。
愛美之心人皆有之。生活質量越來越高的今天,人們對於美的需求亦越來越大。但是網絡上雜而糙的護膚、化妝的信息難以篩選,故而護膚、化妝方面的信息需要有一個整合信息,並且能夠互相交流經驗的平臺。
本網站的設計與實現使用了Python+Flask+MysqL的web建設技術,並且使用HTML和CSS/DIV技術使網站頁面更具靈活性。主要實現了用戶的註冊登錄、文章分類搜索、個人信息、歷史發布等10個功能模塊。
2 網站結構設計
3 模塊詳細設計
3.1 登錄、註冊、登出
3,2個人中心
3.3 修改個人信息
3.4 搜索文章
3.5 文章分類
3.6 發布文章、評論
4 數據庫設計
4.1 E-R圖
4.2 數據字典
表4-2-1 用戶信息表
表中列名 |
數據類型 |
是否為空 |
說明 |
id |
Int |
Not null(主鍵) |
標識id |
username |
String |
Not null |
用戶名 |
_password |
String |
Not null |
密碼 |
icon |
String |
Not null |
頭像文件名 |
表4-2-2 問答信息表
表中列名 |
數據類型 |
是否為空 |
說明 |
id |
int |
Not null(主鍵) |
標識id |
title |
string |
Not null |
題目 |
detail |
text |
Not null |
內容 |
creat_time |
datetime |
Not null |
發布時間 |
author_id |
Int |
Not null(外鍵) |
作者id |
cf |
Int |
Not null(外鍵) |
分類 |
look |
Int |
Not null |
瀏覽量 |
click |
int |
Not null |
點擊量 |
表4-2-3 評論信息表
表中列名 |
數據類型 |
是否為空 |
說明 |
id |
int |
Not null(主鍵) |
標識id |
author_id |
Int |
Not null(外鍵) |
作者id |
question_id |
Int |
Not null(外鍵) |
問答id |
creat_time |
datetime |
Not null |
發布時間 |
detial |
text |
Not null |
內容 |
表4-2-4問答分類信息表
表中列名 |
數據類型 |
是否為空 |
說明 |
id |
Int |
Not null(主鍵) |
標識id |
name |
string |
Not null |
分類名稱 |
表4-2-5收藏信息表
表中列名 |
數據類型 |
是否為空 |
說明 |
id |
Int |
Not null(主鍵) |
標識id |
book_id |
Int |
Not null(外鍵) |
問答id |
collection |
Int |
Not null(外鍵) |
收藏用戶id |
creat_time |
datetime |
Not null |
收藏時間 |
5 系統實現的關鍵算法與數據結構
5.1 登錄、註冊、登出
# 退出 @app.route(‘/logout/‘) def logout(): session.pop(‘username‘) return redirect(url_for(‘index‘)) # 登陸 @app.route(‘/login/‘, methods=[‘GET‘, ‘POST‘]) def login(): if request.method == ‘GET‘: return render_template(‘login.html‘) else: username = request.form.get(‘username‘) password = request.form.get(‘password‘) user = User.query.filter(User.username == username).first() if user: if user.check_password(password): session[‘username‘] = user.username session[‘user_id‘] = user.id session.permanent = True # 重新定位到首頁 return redirect(url_for(‘index‘)) else: # 重新定位到註冊 return redirect(url_for(‘login‘)) else: return redirect(url_for(‘login‘)) # 註冊 @app.route(‘/regist/‘, methods=[‘GET‘, ‘POST‘]) def regist(): if request.method == ‘GET‘: # 打開註冊頁的模板 return render_template(‘regist.html‘) else: # 收到用戶上傳的信息 username = request.form.get(‘username‘) password = request.form.get(‘password‘) user = User.query.filter(User.username == username).first() if user: return ‘error:user exitst‘ else: user = User(username=username, password=password) db.session.add(user) # 加入數據庫 db.session.commit() return redirect(url_for(‘login‘)) # 定義一個裝飾器出驗證用戶有是否是登陸 # 定義一個參數函數 def loginFirst(func): # 定義一個函數將其返回 @wraps(func) def wrapper(*args, **kwargs): if session.get(‘username‘): return func(*args, **kwargs) else: return redirect(url_for(‘login‘)) # 返回一個函數 return wrapper
5.2 個人中心
# 某用戶發布過的所有問題、評論,個人信息、我的收藏 @app.route(‘/comment/<user_id>/<num>‘) def comment(user_id, num): user = User.query.filter(User.id == user_id).first() content = { ‘comment‘: user.comment, ‘questions‘: user.question, ‘user2‘: user, } if (num == ‘1‘): return render_template(‘subComment1.html‘, **content, title=‘全部問題‘) elif (num == ‘2‘): return render_template(‘subComment2.html‘, **content) elif (num == ‘3‘): return render_template(‘subComment3.html‘, **content) elif (num == ‘4‘): content = { ‘comment‘: user.comment, ‘questions‘: user.collection.all(), ‘user2‘: user, } return render_template(‘subComment1.html‘, **content, title=‘我的收藏‘) else: return render_template(‘subComment1.html‘, **content) #修改密碼 @app.route(‘/setPassword/<id>‘, methods=[‘GET‘, ‘POST‘]) @loginFirst def setPassword(id): if request.method == ‘GET‘: return render_template(‘setPassword.html‘) else: user = User.query.filter(User.id == id).first() if user: if user.check_password(request.form.get(‘old‘)): user.password = request.form.get(‘new1‘) db.session.commit() info = ‘修改成功‘ else: info = ‘原密碼錯誤‘ else: info = ‘未知錯誤‘ return redirect(url_for(‘index‘, info=info)) # 上傳頭像 @app.route(‘/uploadLogo/<user_id>‘, methods=[‘GET‘, ‘POST‘]) def uploadLogo(user_id): user = User.query.filter(User.id == user_id).first() f = request.files[‘logo‘] basepath = os.path.dirname(__file__) # 當前文件所在路徑 upload_path = os.path.join(basepath, ‘static/uploads‘, f.filename) # 註意:沒有的文件夾一定要先創建,不然會提示沒有該路徑 f.save(upload_path) user.icon = ‘uploads/‘ + f.filename db.session.commit() return redirect(url_for(‘setPassword‘, id=user_id));
5.3 搜索文章
# 模糊查找 @app.route(‘/search‘) def search(): qu = request.args.get(‘q‘) c = ‘‘ if request.args.get(‘c‘) == ‘‘ else request.args.get(‘c‘) query = Question.query.filter( or_( Question.title.contains(qu), Question.detail.contains(qu), ), Question.cf.like(‘%‘ + c + ‘%‘), ).order_by(‘-creat_time‘).all() context = { ‘questions‘: query, ‘cf‘: Cf.query.all(), ‘hot‘: Question.query.order_by(‘-click‘).all()[0:4] } return render_template(‘index.html‘, **context)
5.4 文章分類
@app.route(‘/‘) def index(): if request.args.get(‘info‘): info = request.args.get(‘info‘) else: info = None context = { ‘questions‘: Question.query.order_by(‘-creat_time‘).all()[0:4], ‘cf‘: Cf.query.all(), ‘info‘: info, ‘hot‘: Question.query.order_by(‘-click‘).all()[0:4] } return render_template(‘index.html‘, **context)
5.5 點贊收藏
@app.route(‘/detail/<question_id>‘, methods=[‘GET‘, ‘POST‘]) @loginFirst def detail(question_id): quest = Question.query.filter(Question.id == question_id).first() u = User.query.filter(User.id == session.get(‘user_id‘)).first() if request.method == ‘POST‘: if request.form.get(‘click‘) == ‘1‘: quest.click = quest.click + 1 if request.form.get(‘collection‘) == ‘1‘: user = u user.collection.append(quest) db.session.add(user) col = u.collection.filter_by(id=question_id).first() if col is None: col = {} comment = Comment.query.filter(Comment.question_id == question_id).order_by(‘-creat_time‘).all() quest.look = quest.look + 1 content = { ‘ques‘: quest, ‘comment‘: comment, ‘col‘: col, ‘questions‘: Question.query.filter(Question.cf == quest.cf).all(), } return render_template(‘detail.html‘, **content)
5.6 發布文章、評論
# 發布問答 @app.route(‘/question‘, methods=[‘GET‘, ‘POST‘]) @loginFirst def question(): if request.method == ‘GET‘: cf = Cf.query.all() return render_template(‘question.html‘, cf=cf) else: title = request.form.get(‘title‘) detail = request.form.get(‘detail‘) author_id = request.form.get(‘author_id‘) cf = request.form.get(‘cf‘) question = Question(title=title, detail=detail, author_id=author_id, cf=cf) db.session.add(question) # 加入數據庫 db.session.commit() return redirect(url_for(‘index‘)) # 發布評論 @app.route(‘/answer/‘, methods=[‘GET‘, ‘POST‘]) def answer(): if request.method == ‘POST‘: question_id = request.form.get(‘question_id‘) author_id = request.form.get(‘author_id‘) detail = request.form.get(‘detail‘) comment = Comment(question_id=question_id, author_id=author_id, detail=detail) db.session.add(comment) db.session.commit() return redirect(url_for(‘detail‘, question_id=question_id))
6 成品展示
6.1首頁
6.2 發布問答頁
6.3 個人中心
6.4 詳情頁
6.5登錄頁
6.6 註冊頁
6.7 搜索
管理信息系統 課程設計