[英]how to use a variable to define a directory flask python3
I have this sample code below, when I try to go to / I get a 404 error, I am trying to use variables as app routes but with no luck我在下面有这个示例代码,当我尝试转到 / 我收到 404 错误时,我正在尝试使用变量作为应用程序路由,但没有运气
from flask import Flask
app = Flask(__name__)
index_dir = "/"
app.route(index_dir)
def index():
return "hello_world"
if __name__ == '__main__':
app.run(host="0.0.0.0")
Any idea on how to make python3 variables to directories关于如何将 python3 变量设置为目录的任何想法
You have skipped the decorator symbol ( @
) before app.route(index_dir)
.您在
app.route(index_dir)
之前跳过了装饰符 ( @
app.route(index_dir)
。 It should be like this to work:工作应该是这样的:
from flask import Flask
app = Flask(__name__)
index_dir = "/"
@app.route(index_dir)
def index():
return "hello_world"
if __name__ == '__main__':
app.run(host="0.0.0.0")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.