完成注册功能
2017-11-22 12:05 082何晓琳 阅读(174) 评论(0) 编辑 收藏 举报from flask import Flask,render_template,request,redirect,url_for 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=True,autoincrement=True) username = db.Column(db.String(20),nullable=False) password = db.Column(db.String(20), nullable=False) nickname = db.Column(db.String(20)) db.create_all() # user=User(username='mis1234',password='111111') # db.session.add(user) # db.session.commit() @app.route('/',methods=['GET','POST']) def register(): if request.method=='GET': return render_template('登录.html') else: username=request.form.get('username') passward=request.form.get('passward') nickname=request.form.get('nickname') user=User.query.filter(User.username==username).first() if user: return 'username existed' else: user=User(username=username,passward=passward,nickname=nickname) db.session.add(user) db.session.commit() return redirect(url_for('登录')) @app.route('/load',methods=['GET','POST']) def load(): if request.method == 'GET': return render_template('登录.html') @app.route('/') def base(): return render_template('base.html') @app.route('/login/') def login(): return render_template('登录.html') @app.route('/signin/') def signin(): return render_template('zhuce.html') @app.route('/fabu/') def fabu(): return render_template('发布.html') if __name__=='__main__': app.run(debug=True) if __name__ == '__main__': app.run()