@app.route('/login', methods = ['POST', 'GET'])
def login():
if request.method == 'POST':
user = request.form['nm']
password = request.form['pwd']
if user_add(user, password) == True:
return url_for('hello', name = user)
else:
return redirect(url_for('incorrect'))
@app.route('/classes', methods = ['POST', 'GET'])
def classes(name):
file.write(#input from classes.html)
我想转到login函数,如果user_add为True,我想执行classes函数并打开此函数使用的classes.html。我该怎么办?
答案 0 :(得分:0)
你在这里要了两件事:
对于问题1,只需使用烧瓶中的redirect
。
from flask import redirect
if user_add(user, password) == True:
return redirect('classes')
然后对于问题2,在类视图中使用来自flask的render_template
from flask import render_template
@app.route('/classes', methods = ['POST', 'GET'])
def classes(name):
return render_templates('classes.html')