1 from flask import Flask 2 #导入重定向和反转模块 3 from flask import redirect,url_for 4 5 app = Flask(__name__) 6 7 @app.route(‘/‘) 8 def index(): 9 login_url = url_for(‘login‘) 10 return redirect(login_url) 11 return ‘这是首页‘ 12 13 @app.route(‘/login/‘) 14 def login(): 15 return u‘这里是登录页面‘ 16 17 @app.route(‘/question/<is_login>/‘) 18 def question(is_login): 19 if is_login == ‘1‘: 20 return u‘这是发布问答页面‘ 21 else: 22 # return redirect(url_for(‘login‘)) 23 return redirect(‘login‘) 24 25 if __name__ == ‘__main__‘: 26 app.run(debug=True)
原文地址:https://www.cnblogs.com/hujc/p/11256964.html
时间: 2024-11-09 18:23:23