@app.context_processor
def mycontext():
usern = session.get('user')
if usern:
return {'username' : usern}
else:
return {}
@app.route('/base/')
def base():
return render_template('base.html')
@app.route('/register/',methods=['GET','POST'])
def register():
if request.method == 'GET':
return render_template('register.html')
else:
username = request.form.get('username')
password = request.form.get('password')
nickname = request.form.get('nickname')
user = User.query.filter( User.username == username).first()
if user:
return'username existed'
else:
user = User(username=username,password=password,nickname=nickname)
db.session.add(user)
db.session.commit()
return redirect(url_for('login'))
@app.route('/fankui/')
def fankui():
return render_template('fankui.html')
@app.route('/logout/')
def logout():
session.clear()
return redirect(url_for('danghangye'))