一篇完整的博客
- 个人学期总结
- 总结Python+Flask+MysqL的web建设技术过程,标准如下:
- 即是对自己所学知识的梳理
- 也可作为初学入门者的简单教程
- 也可作为自己以后复习的向导
- 也是一种向外展示能力的途径
学习管理信息系统这门课程,首先要了解管理信息系统的本质,明确区分信息与数据、信息与知识。对管理信息系统这门课程的理论知识要熟记于心。
众所周知,管理信息系统是为了适应现代化管理的需要,在管理科学、系统科学、信息科学和计算机科学等学科的基础上形成的一门科学,它研究管理系统中信息处理和决策的整个过程,并探讨计算机的实现方法。它是一个由人、计算机、通信设备等硬件和软件组成的,能进行管理信息的收集、加工、存储、传输、维护和使用的系统。管理信息系统可促使企业向信息化方向发展,使企业处于一个信息灵敏、管理科学、决策准确的良性循环之中,为企业带来更高的经济效益。所以,管理信息系统是企业现代化的重要标志,是企业发展的一条必由之路。
信息系统在管理各项事务中有着普遍的应用,促进了企业管理工作的提升。管理信息系统是为管理服务的,它的开发和建立使企业摆脱落后的管理方式,实现管理现代化的有效途径。管理信息系统将管理工作统一化、规范化、现代化,极大地提高了管理的效率,使现代化管理形成统一、高效的系统。过去传统的管理方式是以人为主体的人工操作,虽然管理人员投入了大量的时间、精力,然而个人的能力是有限的,所以管理工作难免会出现局限性,或带有个人的主观性和片面性。而管理信息系统使用系统思想建立起来的,以计算机为信息处理手段,以现代化通信设备为基本传输工具,能力管理决策者提供信息服务的人机系统,这无疑是将管理与现代化接轨,以科技提高管理质量的重大举措。管理信息系统将大量复杂的信息处理交给计算机,使人和计算机充分发挥各自的特长,组织一个和谐、有效的系统,为现代化管理带来便捷。
在现代化管理中,计算机管理信息系统已经成为企业管理不可缺少的帮手,它的广泛应用已经成为管理现代化的重要标志。在企业管理现代化中,组织、方法、控制的现代化离不开管理手段的现代化。随着科学技术的发展,尤其是信息技术和通讯技术的发展,使计算机和网络逐渐应用于现代管理之中。面对越来越多的信息资源和越来越复杂的企业内外部环境,企业有必要建立高效、实用的管理信息系统,为企业管理决策和控制提供保障,这是实现管理现代化的必然趋势。所以我觉得学习管理信息系统是非常必要的,特别是对我们电子商务的学生而言。我觉得平时上课学习是不够的,要更加注重实践操作,并且也要多做练习题,这样有利于更好的了解管理信息系统。
一、 课程实操要求能够熟悉基本的python语言。(IDLE(Phthon 3.6 64-bit))
1、python基础(作业2)
2、用python自带包turtle画图(作业3)
3、熟悉条件、循环、函数语句(作业4)
4、熟悉字符串的基本操作(作业5)
5、了解凯撒密码、GDP格式化输出、循环语句打出九九乘法表(作业6)
6、统计词频预备,组合数据类型的练习(作业7)
7、明确列表list、元组tuple、字典dict、集合的联系与区别,实现列表、元组、字典、集合的遍历(作业8)
8、以文件方式实现完整的英文词频统计(作业9)
9、实现中文词频统计(作业10)
10、使用datetime处理日期和时间(作业11)
11、timestamp、timedelta的使用(作业12)
二、web项目的建立与完善(Pycharm、Mysql、Navicat for MySql)
1、认识URL,观察常用网站网址,区分不同组成部分。观察web浏览过程。尝试使用HTML制作简单页面(作业13)例如:
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>小说中心title>
head>
<body>
<p>
<h1 align="center">小说排行榜第一h1>
<br>
<hr>
<div>
<p align="center">
<img src="https://qidian.qpic.cn/qdbimg/349573/1209977/180 ">
p>
div>
<div>
<p align="center">
<a href="https://book.qidian.com/info/1209977"><img src="URL" alt="斗破苍穹">a>
p>
div>
p>
body>
html>
2、练习使用下拉列表选择框,无序列表,有序列表,定义列表。(作业14)
下拉列表 <select> <option>收藏option> <option>点赞option> <option>评论option> <option>打赏option> select>
无序列表 <ul> <li>作者排行榜li> <li>作品排行榜li> ul>
有序列表 <ol> <li>收藏排行榜li> <li>评论排行榜li> <li>点赞排行榜li> <li>打赏排行榜li> ol>
定义列表 <dl> <dt>最爱小说dt> <dd>玄幻dd> dl>
3、练习使用导航条与HTML头部元素(简单CSS)。(作业15)
<nav> #导航条 <a href="http://localhost:59137/aaa/templates/lx.html?_ijt=piaotqep9pl034qe7m6iulfk3j"> <img src="http://img.qq1234.org/uploads/allimg/140530/0959191046-157.png" width="30px" height="30px">a> <a href="https://baike.so.com/doc/1975803-2090971.html">百科a> <input type="text" style="background-color: antiquewhite"> <select name="" id="">select> <button type="submit">搜索button> nav>
<head> <meta charset="UTF-8"> <title>BIUBIUBIUtitle> {# <base> 定义了页面链接标签的默认链接地址#} <base href="" target="_blank"> {# <link> 定义了一个文档和外部资源之间的关系#} <link rel="stylesheet" href="style.css"> {#行内样式#} <style> .l{background-color: bisque;font-family: 楷体;color: brown} #k{color: cadetblue;font-family: "Freestyle Script";font-size: 150px} style> head>
4、CSS实例——图片导航块(作业16)
{#class引用#}
.img {
border: 1px solid #cccccc;
width: 250px;
margin: 5px;
float: left;
}
div.img img {
width: 100%;
height: auto;
}
div.desc{
text-align: center;
padding: 5px;
}
div.img:hover{
border: 1px solid #000000;
}
.area {
height: 300px;
}
.area1 {
height: 180px;
}
5、JS基础、验证表单提交的条件。(作业17)
<script> function fnLogin() { var oUname = document.getElementById("uname") {#错误提示框#} var oError = document.getElementById("error_box") var oUword = document.getElementById("uword") if(oUname.value.length<6){ oError.innerHTML = "用户名至少4位" } if(oUname.value.length==0){ oError.innerHTML = "请输入用户名" } if(oUname.value.length>12){ oError.innerHTML = "用户名至多13位" } if(oUword.value.length==0){ oError.innerHTML = "请输入密码" } if(oUword.value.length<6){ oError.innerHTML = "密码至少6位" } if(oUword.value.length>20){ oError.innerHTML = "密码至多20位" } } script>
6、完成登录、注册页面的HTML+CSS+JS。(作业18)
7、制作父模板base.html。(作业19)
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>basetitle>
{#链接到CSS文件#}
<link rel="stylesheet" href="../static/css/base.css" type="text/css">
{#链接到JS文件#}
<script src="../static/JS/base.js">script>
head>
<body id="myBody">
{#导航条#}
<nav>
<img id="myOnOff" onclick="mySwitch()"
src="http://img3.redocn.com/tupian/20150409/shouhuihuangsetaiyangshiliangsucai_4034066.jpg" width="30px">
<a href="http://localhost:63342/denglu1.1/templates/shouye.html?_ijt=qijfc55i74avkg8umf7nn7oqt7">首页a>
<a href="http://localhost:63342/denglu1.1/templates/denglu1.1.html?_ijt=7qkhljvviqhhrvp78f6nv1jtqn">Logina>
<a href="http://localhost:63342/denglu1.1/templates/%E6%B3%A8%E5%86%8C.html?_ijt=bpr6ikepnp2sh7actb82n1m3dt">Enrolla>
nav>
<div class="area">
div>
<div class="area1">
<div class="img">
<a href="http://image.so.com/i?src=360pic_strong&z=1&i=2&cmg=5fa9918b43bdd880a720ad048811374f&q=猫">
<img src="http://attachments.gfan.com/forum/201503/18/213547yy3u5muo8v3j3r6f.jpg">a>
<div class="desc"><a
href="http://image.so.com/i?src=360pic_strong&z=1&i=2&cmg=5fa9918b43bdd880a720ad048811374f&q=猫">miowa>
div>
div>
div>
<div>
HTML design by 201508030006 陈文琪
div>
body>
html>
8、使用flask。(作业20)
#主程序 from flask import Flask,render_template app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/login/') def login(): return render_template('login.html') @app.route('/regist/') def regist(): return render_template('regist.html') if __name__ == '__main__': app.run(debug=True)
{#base.html调用主程序url_for#} <nav> <img id="myOnOff" onclick="mySwitch()" src="http://img3.redocn.com/tupian/20150409/shouhuihuangsetaiyangshiliangsucai_4034066.jpg" width="30px"> <a href="{{ url_for('index') }}">首页a> <a href="{{ url_for('login') }}">登录a> <a href="{{ url_for('regist') }}">立即注册a> nav>
9、用url_for加载静态文件,继承父模板。(作业21)
<script src="{{ url_for('static',filename='js/login.js') }}">script>
{% extends 'base.html' %} }{#继承父模板#} {% block title %}首页{% endblock %} {% block main %} <h1>首页h1> {% endblock %}
10、带
<div class="q1"> <label for="question">问题label> <textarea id="question" cols="50" rows="1">textarea> div>
11、连接数据库MySQL,创建用户模型。(作业23)
#MySQL连接文件 SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:@localhost:3306/test?charset=utf8' SQLALCHEMY_TRACK_MODIFICATIONS = False
#建立MySQL和app的连接 from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy import config app = Flask(__name__) app.config.from_object(config) db = SQLAlchemy(app) #创建用户模型 class User(db.Model): __tablename__ = 'User' id = db.Column(db.Integer, primary_key=TabError, autoincrement=True) username = db.Column(db.String(20), nullable=False) password = db.Column(db.String(20), nullable=False) db.create_all(
12、练习对数据库的增删改查。(作业24)
# 创建用户 user=User(username='meow2',password='meow2222',nickname='miao~') db.session.add(user) db.session.commit() #查询 user=User.query.filter(User.username=='meow1').first() print(user.username,user.password) # 修改密码 user=User.query.filter(User.username=='meow1').first() user.password='9999999999999' db.session.commit() # 删除 user=User.query.filter(User.username=='meow2').first() db.session.delete(user) db.session.commit()
13、写JS文件,onclick函数return true时才提交表单。(作业25)
function fnRegist() { var zcoUname = document.getElementById("zcuname") var zcoError = document.getElementById("zcerror_box") zcoError.innerHTML = "
" if (zcoUname.value.length < 6 || zcoUname.value.length > 12) { zcoError.innerHTML = "用户名为6到12位"; return false } return true }
<form action="{{ url_for('regist') }}" method="post"> ...... <button onclick="fnRegist()">立即注册button>
14、用session记住登录的用户名传到页面。(作业26)
@app.route('/login/', methods=['GET', 'POST']) def login(): if request.method=='GET': return render_template('login.html') else:#读取表单数据 usern = request.form.get('username') passw = request.form.get('password') user = User.query.filter(User.username == usern,User.password==passw).first()#查找对应的用户名、密码 if user: session['user']=usern session.permanent=True return redirect(url_for('index')) else: return u'用户名不存在/密码错误'
15、在模板中做导航。(作业27)
@app.context_processor#上下文处理器定义函数 def mycontext(): usern=session.get('user')#获取session中保存的值 if usern: return {'username':usern}#返回字典 else: return {}
{% if username %} <li><a href="#">{{ username }}a>li> <li><a href="#">注销a>li> {% else %} <li><a href="{{ url_for('login') }}">登录a>li> <li><a href="{{ url_for('regist') }}">立即注册a>li> {% endif %}
@app.route('/logout/')#注销功能 def logout(): session.clear()#清除session中保存的值 return redirect(url_for('index'))
16、编写并应用登录装饰器,完成发布功能。(作业28)
def loginFrist(func):#参数是函数 @wraps(func) def wrapper(*args, **kwargs):#定义个函数将其返回 if session.get('user'): return func(*args, **kwargs) else: #要求登录 return redirect(url_for('login')) return wrapper
@app.route('/question/', methods=['GET', 'POST']) @loginFrist#应用装饰器,发布前先登录 def question(): if request.method == 'GET': return render_template('question.html') else: title = request.form.get('title') detail = request.form.get('detail') author_id = User.query.filter(User.username == session.get('user')).first().id question = Question(title=title, detail=detail, author_id=author_id) db.session.add(question) db.session.commit()#保存到数据库 return redirect(url_for('index'))#重定向到首页
17、尝试在首页显示问答列表。(作业29)
18、在首页显示全部问答。(作业30)
@app.route('/') def index():#将数据库查询结果传递到前端页面 context={ 'questions':Question.query.order_by('-creat_time').all() } return render_template('index.html',**context)
{% for foo in questions %}#前端页面循环显示整个列表。 <li class="list-group-item"> <span class="glyphicon glyphicon-leaf" aria-hidden="true">span> <a href="#">{{ foo.author.username }}a><br> <a href="{{ url_for('detail',question_id=foo.id) }}" class="title">{{ foo.title }}a> <span class="badge">{{ foo.creat_time }}span> <p class="detail">{{ foo.detail }}p> li> {% endfor %}
19、首页文章标题链接详情页。(作业31)
@app.route('/detail/')#视图函数,带id参数 def detail(question_id):#查询对应的文章详情 quest=Question.query.filter(Question.id==question_id).first() return render_template('detail.html',quest=quest)#返回详情
<a href="{{ url_for('detail',question_id=foo.id) }}" class="title">{{ foo.title }}a>#首页文章title链接详情
20、评论功能的实现。(作业32)
@app.route('/comment/', methods=['POST']) @loginFrist#评论前登录 def comment():#读取页面数据 comment_detail = request.form.get('new_comment') quest_id = request.form.get('question_id') author_id = User.query.filter(User.username == session.get('user')).first().id comment = Comment(detail=comment_detail, author_id=author_id, question_id=quest_id, ) db.session.add(comment)#保存到数据库 db.session.commit() return redirect(url_for('detail', question_id=quest_id))
<input type="hidden" name="question_id" value="{{ quest.id }}">#获取前端的"question_id"
21、在详情页显示该文章所有评论。(作业33)
{% for foo in quest.comments %}#循环显示所有评论 <li class="list-group-item"> <a href="#">{{ foo.author.username }} a> <span class="badge">{{ foo.creat_time }}span> <p>{{ foo.detail }}p> li> {% endfor %}
22、个人中心。(作业33、34、35)
@app.route('/usercenter// ') @loginFrist def usercenter(user_id,tag): user=User.query.filter(User.id==user_id).first() context={ 'user':user, 'nickname':user.nickname, 'comments':user.comments, 'questions':user.question, } if tag == '1':#三个标签页 return render_template('usercenterQ.html', **context) elif tag == '2': return render_template('usercenterC.html', **context) elif tag == '3': return render_template('usercenterI.html', **context)
23、搜索功能。(作业36)
@app.route('/search/') def search(): q=request.args.get('q')#获取页面传入数据 qu=Question.query.filter(or_(Question.title.contains(q),Question.detail.contains(q))).order_by('-creat_time')#条件查询 return render_template('index.html',question=qu)
<form action="{{ url_for('search') }}" methods="get" class="navbar-form navbar-left"> <input name="q" type="text" class="form-control" placeholder="请输入关键字"> <input type="submit" class="btn-default" value="sou"> form>
三、完整代码。
#主PY文件 from flask import Flask, render_template, request, redirect, url_for, session import config from functools import wraps from sqlalchemy import or_ from werkzeug.security import generate_password_hash,check_password_hash from datetime import datetime from flask_sqlalchemy import SQLAlchemy app=Flask(__name__) app.config.from_object(config) db = SQLAlchemy(app) # db.init_app(app) class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=TabError, autoincrement=True) username = db.Column(db.String(20), nullable=False) _password = db.Column(db.String(200), nullable=False)#内部使用 nickname = db.Column(db.String(20)) @property def password(self):#外部使用 return self._password @password.setter def password(self,row_password): self._password=generate_password_hash(row_password) def check_password(self,row_password): result=check_password_hash(self._password,row_password) return result class Question(db.Model): __tablename__ = 'question' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(100), nullable=False) detail = db.Column(db.Text, nullable=False) creat_time = db.Column(db.DateTime, default=datetime.now) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) author = db.relationship('User', backref=db.backref('question')) class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True, autoincrement=True) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) question_id = db.Column(db.Integer, db.ForeignKey('question.id')) creat_time = db.Column(db.DateTime, default=datetime.now) detail = db.Column(db.Text, nullable=False) question = db.relationship('Question', backref=db.backref('comments', order_by=creat_time.desc)) author = db.relationship('User', backref=db.backref('comments')) db.create_all() ''' db.session.add(user) db.session.commit() # 创建用户 user=User(username='meow2',password='meow2222',nickname='miao~') db.session.add(user) db.session.commit() # 修改密码 user=User.query.filter(User.username=='meow1').first() user.password='AAAAAAAAAAA' db.session.commit() # 删除 user=User.query.filter(User.username=='meow2').first() db.session.delete(user) db.session.commit() # 查询 user=User.query.filter(User.username=='meow1').first() print(user.username,user.password) ''' # 装饰器 def loginFrist(func): @wraps(func) def wrapper(*args, **kwargs): if session.get('user'): return func(*args, **kwargs) else: return redirect(url_for('login')) return wrapper # 首页 @app.route('/') def index(): context = { 'questions': Question.query.order_by('-creat_time').all() } return render_template('index.html', **context) # 登录 @app.route('/login/', methods=['GET', 'POST']) def login(): if request.method == 'GET': return render_template('login.html') else: usern = request.form.get('username') passw = request.form.get('password') user = User.query.filter(User.username == usern).first() if user: if user.check_password(passw): session['user'] = usern session['userid']=user.id session.permanent = True return redirect(url_for('index')) else: return u'password is error' else: return u'用户名不存在' @app.context_processor def mycontext(): usern = session.get('user') if usern: return {'username': usern} else: return {} # 注销 @app.route('/logout/') def logout(): session.clear() return redirect(url_for('index')) # 问答 @app.route('/question/', methods=['GET', 'POST']) @loginFrist def question(): if request.method == 'GET': return render_template('question.html') else: title = request.form.get('title') detail = request.form.get('detail') author_id = User.query.filter(User.username == session.get('user')).first().id question = Question(title=title, detail=detail, author_id=author_id) db.session.add(question) db.session.commit() return redirect(url_for('index')) # 详情页 @app.route('/detail/') def detail(question_id): quest = Question.query.filter(Question.id == question_id).first() return render_template('detail.html', quest=quest) # 评论 @app.route('/comment/', methods=['POST']) @loginFrist def comment(): comment_detail = request.form.get('new_comment') quest_id = request.form.get('question_id') author_id = User.query.filter(User.username == session.get('user')).first().id comment = Comment(detail=comment_detail, author_id=author_id, question_id=quest_id, ) db.session.add(comment) db.session.commit() return redirect(url_for('detail', question_id=quest_id)) # 注册 @app.route('/regist/', methods=['GET', 'POST']) def regist(): if request.method == 'GET': return render_template('regist.html') else: # 获取form中的数据,判断用户名是否存在,存到数据库中 username = request.form.get('username') nickname = request.form.get('nickname') password = request.form.get('password') user = User.query.filter(User.username == username).first() # 重定向到登录页 if user: return u'用户名已存在' else: user = User(username=username, nickname=nickname, password=password) db.session.add(user) db.session.commit() return redirect(url_for('login')) # 用户中心 @app.route('/usercenter/ / ') @loginFrist def usercenter(user_id,tag): user=User.query.filter(User.id==user_id).first() context={ 'user':user, 'nickname':user.nickname, 'comments':user.comments, 'questions':user.question, } if tag == '1': return render_template('usercenterQ.html', **context) elif tag == '2': return render_template('usercenterC.html', **context) elif tag == '3': return render_template('usercenterI.html', **context) # 搜索 @app.route('/search/') def search(): q=request.args.get('q') qu=Question.query.filter(or_(Question.title.contains(q),Question.detail.contains(q))) return render_template('index.html',questions=qu) if __name__ == '__main__': app.run(debug=True)
#模板 DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> {% block title %} {% endblock %}-Montitle> <link rel="stylesheet" href="{{ url_for('static',filename='css/base.css') }}"> <script src="{{ url_for('static',filename='JS/base.js') }}">script> {% block head %} {% endblock %} head> <body id="myBody"> <nav class="nav nav-tabs"> <li> <img id="myOnOff" onclick="mySwitch()" src="http://img3.redocn.com/tupian/20150409/shouhuihuangsetaiyangshiliangsucai_4034066.jpg" width="30px"> li> <li><a href="{{ url_for('index') }}">首页a>li> <li><a href="{{ url_for('question') }}">发帖a>li> <form action="{{ url_for('search') }}" methods="get" class="navbar-form navbar-left"> <div class="form-group"> <input name="q" type="text" class="form-control" placeholder="请输入关键字"> div> <input type="submit" class="btn-default" value="so~"> form> <ul class="nav navbar-nav navbar-right"> {% if username %} <li><a href="{{ url_for('usercenter',user_id=session.get('userid'),tag=1) }}">{{ session.get('user') }}a>li> <li><a href="{{ url_for('logout') }}">注销a>li> {% else %} <li><a href="{{ url_for('login') }}">登录a>li> <li><a href="{{ url_for('regist') }}">立即注册a>li> {% endif %} <li><img src="{{ url_for( 'static',filename='image/meow.jpg') }}" width="30px">li> ul> nav> {% block main %} <div class="area"> div> {% endblock %} <div class="area1"> <div class="img"> <a href="https://baike.so.com/doc/5040370-5267074.html"><img src="{{ url_for( 'static',filename='image/meow1.jpg') }}">a> <div class="desc"><a href="https://baike.so.com/doc/5040370-5267074.html">薛定谔的猫a>div> div> <div class="img"> <a href="https://www.zhihu.com/question/30454189"> <img src="{{ url_for( 'static',filename='image/meow3.jpg') }}"> a> <div class="desc"><a href="https://www.zhihu.com/question/30454189">中华田园猫的颜值可以多高?a>div> div> <div class="img"> <a href="http://image.so.com/i?src=360pic_strong&z=1&i=2&cmg=5fa9918b43bdd880a720ad048811374f&q=猫"> <img src="{{ url_for( 'static',filename='image/meow2.jpg') }}">a> <div class="desc"><a href="http://image.so.com/i?src=360pic_strong&z=1&i=2&cmg=5fa9918b43bdd880a720ad048811374f&q=猫">meowa> div> div> div> body> html>
#首页 {% extends 'base.html' %} } {% block title %}首页{% endblock %} {% block head %} <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="{{ url_for('static',filename='css/index.css') }}"> {% endblock %} {% block main %} <p class="wenhao">welcome {{ username }}p> <h1 style="text-align: center">首页h1> <h2 style="text-align: center">meow meow meow~~h2> <div> <ul class="news-list"> {% for foo in questions %} <li class="list-group-item"> <span class="glyphicon glyphicon-book" style="color: rgb(0, 14, 54);" aria-hidden="true">span> <a href="{{ url_for('detail',question_id=foo.id) }}" class="title">{{ foo.title }}a> <p class="detail">{{ foo.detail }}p> <span class="glyphicon glyphicon-user" aria-hidden="true">span> <a href="{{ url_for('usercenter',user_id=foo.author.id,tag=1) }}">{{ foo.author.username }} 评论:({{ foo.comments|length }})a> <span class="badge">{{ foo.creat_time }}span> li> {% endfor %} ul> div> {% endblock %}
#登录 {% extends 'base.html' %} } {% block title %}登录{% endblock %} {% block head %} <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="{{ url_for('static',filename='css/login.css') }}"> <script src="{{ url_for('static',filename='JS/login.js') }}">script> {% endblock %} {% block main %} <div class="box"> <h2 class="denglu">登录h2> <form action="{{ url_for('login') }}" method="post" onsubmit="true"> <div class="input_box"> <input id="uname" name="username" type="text" placeholder="请输入用户名"> div> <div class="input_box"> <input id="uword" name="password" type="password" placeholder="请输入密码"> div> <div id="error_box"><br>div> <div class="input_box"> <button onclick="fnLogin()">登录button> div> form> <a href="{{ url_for('regist') }}"> <button>立即注册button> a> div> {% endblock %}
#注册 {% extends 'base.html' %} } {% block title %}注册{% endblock %} {% block head %} <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="{{ url_for('static',filename='css/regist.css') }}"> <script src="{{ url_for('static',filename='JS/regist.js') }}">script> {% endblock %} {% block main %} <div class="zcbox"> <h2 class="zhuce">注册h2> <form action="{{ url_for('regist') }}" method="post" onsubmit="return fnRegist()"> <div class="zcinput_box"> <input id="zcuname" type="text" placeholder="请输入用户名" name="username"> div> <div class="zcinput_box"> <input id="zcunickname" type="text" placeholder="请输入昵称" name="nickname"> div> <div class="zcinput_box"> <input id="zcuword1" type="password" placeholder="请输入密码" > div> <div class="zcinput_box"> <input id="zcuword2" type="password" placeholder="请再次输入密码" name="password"> div> <div id="zcerror_box"><br>div> <div class="zcinput_box"> <input type="submit" value="立即注册">input> div> form> div> {% endblock %}
#发帖 {% extends 'base.html' %} } {% block title %}发布帖子{% endblock %} {% block head %} <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="{{ url_for('static',filename='css/question.css') }}"> <script src="{{ url_for('static',filename='JS/question.js') }}">script> {% endblock %} {% block main %} <p>{{ username }},welcomep> <div class="label0"> <h1>发帖h1> <form action="{{ url_for('question') }}" method="post" > <div class="q1"> <label for="question" >主题label> <textarea id="question" cols="77" rows="1" name="title" id="title">textarea> div> <div class="detail"> <label for="questionDetail">详情label> <textarea id="questionDetail" cols="77" rows="5" name="detail" id="detail">textarea> div> <div id="error_box"><br>div> <div class="input-area"> <input type="submit" value="立即发布">input> div> form> div> {% endblock %}
#详情页 {% extends 'base.html' %} } {% block title %}详情页{% endblock %} {% block head %} <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> {% endblock %} {% block main %} <div class="container"> <div class="row clearfix"> <div class="page-header"> <h3>{{ quest.title }}<br> <small><a href="{{ url_for('usercenter',user_id=quest.author.id,tag=1) }}">{{ quest.author.username }}a> <span class="badge">{{ quest.creat_time }}span>small> h3> div> <p class="lead">{{ quest.detail }}p> <hr> <form role="form" action="{{ url_for('comment') }}" method="post"> <div class="form-group"> <label for="exampleInputEmail1">Write down your answer~~label> <textarea class="form-control" id="" name="new_comment">textarea> <input type="hidden" name="question_id" value="{{ quest.id }}"> div> <button type="submit" class="btn btn-default">Submitbutton> <h4>评论:({{ quest.comments|length }})h4> <ul class="news-list"> {% for foo in quest.comments %} <li class="list-group-item"> <a href="{{ url_for('usercenter',user_id=foo.author.id,tag=1) }}">{{ foo.author.username }} a> <span class="badge">{{ foo.creat_time }}span> <p>{{ foo.detail }}p> li> {% endfor %} ul> form> div> div> {% endblock %}
#个人中心模板 {% extends 'base.html' %} } {% block title %}用户中心{% endblock %} {% block head %} <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> {% endblock %} {% block main %} <h3><span class="glyphicon glyphicon-fire" style="color: rgb(98, 0, 28); font-size: 22px;" aria-hidden="true"> span>{{ user.username }}h3> <ul class="nav nav-tabs"> <li role="presentation" class="active"><a href="{{ url_for('usercenter',user_id=user.id,tag=1) }}">发过的帖子a> li> <li role="presentation" class="active"><a href="{{ url_for('usercenter',user_id=user.id,tag=2) }}">发过的评论a> li> <li role="presentation" class="active"><a href="{{ url_for('usercenter',user_id=user.id,tag=3) }}">个人信息a> li> ul> {% block user %} <div class="area"> div> {% endblock %} {% endblock %}
#个人中心——评论标签页 {% extends 'user.html' %} } {% block head %} <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> {% endblock %} {% block user %} <br> <div class="page-header"> <ul class="news-list"> {% for foo in comments %} <li class="list-group-item"> <span class="glyphicon glyphicon-flash" style="color: rgb(124, 0, 28); " aria-hidden="true">span> <a href="#">{{ foo.author.username }} a> <span class="badge">{{ foo.creat_time }}span> <p>{{ foo.detail }}p> li> {% endfor %} ul> div> {% endblock %}
#个人中心——个人信息页 {% extends 'user.html' %} } {% block user %} <br> <div class="page-header"> <ul class="news-list"> <li class="list-group-item"> <span class="glyphicon glyphicon-heart" style="color: rgb(124, 0, 28); " aria-hidden="true">span> Username: {{ user.username }} li> <li class="list-group-item"> <span class="glyphicon glyphicon-heart" style="color: rgb(124, 0, 28); " aria-hidden="true">span> Nickname: {{ nickname }} li> <li class="list-group-item"> <span class="glyphicon glyphicon-heart" style="color: rgb(124, 0, 28); " aria-hidden="true">span> 文章数: {{ questions|length }} li> ul> div> {% endblock %}
#个人中心——帖子页 {% extends 'user.html' %} } {% block head %} <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> {% endblock %} {% block user %} <br> <div class="page-header"> <ul class="news-list"> {% for foo in questions %} <li class="list-group-item"> <span class="glyphicon glyphicon-file" style="color: rgb(124, 0, 28); " aria-hidden="true">span> <a href="#">{{ foo.author.username }} a> <span class="badge">{{ foo.creat_time }}span> <p>{{ foo.detail }}p> li> {% endfor %} ul> div> {% endblock %}