-
- 期末作品检查:基本要求
- 检查时间:18最后四节课,上课之前必须全部完成,上课做基本部署就开始检查
- 方式:逐个运行演示,抽查代码
- 主题:选一个主题,整个网站风格统一,布局合理,尽量美观。
- 期末作品检查:必须完成:
- 网站父模板统一布局:头部导航条、底部图片导航、中间主显示区域布局
- 注册、登录、注销
- 发布、列表显示
- 详情页
- 评论、列表显示
- 个人中心
- 搜索,条件组合搜索
- 一篇完整的博客
- 个人学期总结
- 总结Python+Flask+MysqL的web建设技术过程,标准如下:
- 即是对自己所学知识的梳理
- 也可作为初学入门者的简单教程
- 也可作为自己以后复习的向导
- 也是一种向外展示能力的途径
- 期末作品检查:加分功能
- 文章分类、显示
- 点赞、收藏
- 修改密码、头像、上传头像
- 我的
- 高级搜索
{% extends 'base.html' %} {% block title %}注册界面{% endblock %} {% block head %} <script type="text/javascript" src="{{ url_for('static',filename='js/login.js') }}"></script> {% endblock %} {% block main %} <form action="{{ url_for('login') }}" method="post"> <br><br> <div class="input_box"> Username:<input id="uname" type="text" placeholder="请输入用户名"><br><br><br><br> Password:<input id="upass" type="password" placeholder="请输入密码"><br><br><br></div> <div id="error_box"></div> <div><button id="login" type="submit" οnclick="myLogin()">登录</button></div> </div> </body> </form> {% endblock %}
{% extends 'base.html' %} {% block title %}注册界面{% endblock %} {% block head %} <script type="text/javascript" src="{{ url_for('static',filename='js/register.js') }}"></script> {% endblock %} {% block main %} <form action="{{ url_for('register') }}" method="post"> <br><br>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>{% block title %}首页{% endblock %}</title> <script src="{{ url_for('static',filename='js/base.js') }}" type="text/javascript"></script> {% block head %}{% endblock %} </head> <body id="myBody"> <nav class="daohang"> <div class="daohang_box"> <a class="shouye" href="{{ url_for('base') }}">首页</a> <a class="xiaoqu1" href="{{ url_for('login') }}">登录</a> <a class="xiaoqu2" href="{{ url_for('register') }}">注册</a> <a class="xiaoqu2" href="{{url_for('question')}}">问答</a> <input id="search_box" type="text" placeholder="请输入关键词查找"> <button id="search" type="submit">搜索</button> <link rel="stylesheet" type="text/css" href="../static/css/text.css"> <div class="aimg"> <script> function mySwitch() { var myele = document.getElementById("on_off") if (myele.src.match("bulbon")) { myele.src = "http://www.runoob.com/images/pic_bulboff.gif" document.getElementById("myBody").style.background = "white" document.getElementById("myBody").style.color = "black" } else { myele.src = "http://www.runoob.com/images/pic_bulbon.gif" document.getElementById("myBody").style.background = "black" document.getElementById('myBody').style.color = "white" } } </script> <body id="myBody"> <img id="on_off" οnclick="mySwitch()" src="http://www.runoob.com/images/pic_bulbon.gif" width="50px"> </body></div></div></nav></body></html> <br><br> <!-- 要加的代码,主页部分区别于登录注册界面--> {% block main %} <h2 align="center">首页</h2> <ul > <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> <form> <select> <option>列表</option> <option>收藏</option> </select> </form> <table border="1"> <tr> <th>标题</th> <th>标题</th> <th>标题</th> <th>标题</th> </tr> <tr> <td>行一</td> </tr> </table> <link rel="stylesheet" type="text/css" href="../static/css/text.css"> <div class="aaa" align="center"> <img src="{{ url_for('static',filename='images/cat.jpg') }}"> </a></div> <br><br> {% endblock %} <link rel="stylesheet" type="text/css" href="../static/css/text.css"> <div class="footer" align="center"> 版权 © emmmmmm </div> </html>
{% extends 'base.html' %} {% block title %}发布问答{% endblock %} {% block head %} <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/question.css') }}"> {% endblock %} {% block main %} <div class="fa"> <h1>发布问答</h1> <form action="{{ url_for('question') }}" method="post"> <div class="zhuti"> <label for="question">问题</label><br> <input id="question" type="text" name="title"></div><br> <div class="fa-question"> <label for="questionDetial">详情</label><br> <textarea id="questionDetial" rows="12" name="detail"></textarea></div> <div class="check"><input type="checkbox">check me out</div> <button class="sumbit" type="submit">提交</button> </form> </div> {% endblock %}
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" type="text/css" href="../static/css/text.css"> <div class="img" > <script> function mySwitch() { var myele = document.getElementById("on_off") if (myele.src.match("bulbon")) { myele.src = "http://www.runoob.com/images/pic_bulboff.gif" document.getElementById("myBody").style.background = "white" document.getElementById("myBody").style.color = "black" } else { myele.src = "http://www.runoob.com/images/pic_bulbon.gif" document.getElementById("myBody").style.background = "black" document.getElementById('myBody').style.color = "white" } } </script> <body id="myBody"> <img id="on_off" οnclick="mySwitch()" src="http://www.runoob.com/images/pic_bulbon.gif" width="50px"> </body></div> <h2 align="center">发布中心</h2> <hr> </head> <body> <h2 align="center">发布问答 </h2> <label for="questiontitle" class="col-sm-2 control-label">发布</label> <div class="col-sm-10"> <input type="text"class="form-control" id="questiontitle" rows="5" cols="87"> </div> <div class="form-group"> <label for="questiontext" class="col-sm-2 control-label">评论</label> <div class="form-group"> <textarea id="questiontext" class="form-control" rows="6" id="comment" placeholder="请输入评论"></textarea> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default">提交</button> </div> </div> </form> </div> </div></div> </body> </html>
import os #DEBUG=True SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:@127.0.0.1:3306/login_db?charset=utf8' SQLALCHEMY_TRACK_MODIFICATIONS = False SECRET_KEY = os.urandom(24)
function myRegister() { var oUname = document.getElementById("uname"); var oError = document.getElementById("error_box"); var oUpass = document.getElementById("upass"); var oConfirm=document.getElementById("uconfirmrpass") var oUtel = document.getElementById("utel"); var isError = true; oError.innerHTML="<br>" if ((oUname.value.length<6)||(oUname.value.length>20)){ oError.innerHTML = "用户名6位必须6-20" isError = false; return isError; } else if((oUname.value.charCodeAt(0)>=48)&&(oUname.value.charCodeAt(0)<=57)){ oError.innerHTML = "用户名首位必须为字母" isError = false; return isError; } else for(var i=0;i<oUname.value.length;i++) { if ((oUname.value.charCodeAt(i) < 48 || oUname.value.charCodeAt(i) > 57) && (oUname.value.charCodeAt(i) < 97 || oUname.value.charCodeAt(i) > 122)) { oError.innerHTML = "用户名必须为字母或数字" isError = false; return isError; } } if(oUtel.value.length!=11){ oError.innerHTML = "电话号码必须为11位" isError = false; return isError; } else for(var i=0;i<oUname.value.length;i++) { if (oUtel.value.charCodeAt(i) < 48 || oUtel.value.charCodeAt(i) > 57) { oError.innerHTML = "电话号码必须为数字" isError = false; return isError; } } if ((oUpass.value.length<6)||(oUpass.value.length>20)) { oError.innerHTML = "密码必须6-20位" isError = false; return isError; } else if(oConfirm.value!=oUpass.value){ oError.innerHTML = "两次输入的密码不一致" isError = false; return isError; } return isError; window.alert("注册成功")
from flask import Flask, render_template, request, redirect, url_for,session from flask_sqlalchemy import SQLAlchemy from functools import wraps from datetime import datetime import congfig app = Flask(__name__) app.config.from_object(congfig) db = SQLAlchemy(app) class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True, autoincrement=True) Username = db.Column(db.String(20), nullable=False) Password = db.Column(db.String(20), nullable=False) Telphone=db.Column(db.String(20), nullable=True) #db.create_all() class Question(db.Model): __tablename__ = 'question' id = db.Column(db.Integer, primary_key=True, autoincrement=True) author_id = db.Column(db.Integer,db.ForeignKey('user.id')) 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 = db.relationship('User', backref=db.backref('question')) @app.route('/') def base(): return render_template('base.html') @app.route('/login/', methods=['GET', 'POST']) def login(): if request.method == 'GET': return render_template('login.html') else: usern = request.form.get('a') passn = request.form.get('b') user = User.query.filter(User.Username == usern).first() if user: if user.Password == passn: session['user'] = usern return redirect(url_for('question')) else: return '密码错误' # return window.alert("密码错误") else: # return window.alert("用户名不存在") return '用户名不存在' @app.context_processor def mycontext(): usern = session.get('user') if usern: return {'Username': usern} else: return {} def login_re(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('/logout/') def logout(): session.clear() return redirect(url_for("base")) @app.route('/register/', methods=['GET', 'POST']) def register(): if request.method == 'GET': return render_template('register.html') else: usern = request.form.get('a') passn=request.form.get('b') teln=request.form.get('c') user=User.query.filter(User.Username==usern).first() if user: return '用户名已经存在' else: user1=User(Username=usern,Password=passn,Telphone=teln) db.session.add(user1) db.session.commit() return redirect(url_for('login')) @app.route('/question/', methods=['GET', 'POST']) def question(): if request.method == 'GET': return render_template('question.html') else: an = User.query.filter(User.Username == session.get('user')).first().id tn= request.form.get('title') dn = request.form.get('detail') question1 = Question(author_id=an,title=tn, detail=dn) # question.author=User db.session.add(question1) # 数据库,添加操作 db.session.commit() #提交 return redirect(url_for('question')) if __name__ == '__main__': app.run(debug=True)
<div class="input_box"> 请输入昵称:<input id="uname" type="text" placeholder="6-20位首位必须为字母" name="a"><br><br> 输入手机号:<input id="utel" type="text" placeholder="T11位" name="b"><br><br> 设置密码:<input id="upass" type="password" placeholder="6-20位" name="c"><br><br> 确认密码:<input id="uconfirmrpass" type="password" placeholder="Confirmpass" name="d"><br><br></div> <div id="error_box"></div> <div> <button id="register" type="submit" οnclick="myRegister()">注册</button> </div> </div> </form> {% endblock %}
- 期末作品检查:基本要求
转载于:https://www.cnblogs.com/caoxinwen092/p/8206860.html