404使用Flask应用程序的本地计算机出错

2024-05-01 22:05:58 发布

您现在位置:Python中文网/ 问答频道 /正文

在这篇文章的开头,我先说一下,我熟悉Python作为一种数据工具,但这是我第一次使用Python/Flask。。。。我正在努力阅读Flask Mega教程,并决定尝试为公司销售团队制作一个仪表板。我刚开始,我不知道我做错了什么。在

Here是Github上我项目的链接我想这是因为导入是循环的??但我不知道怎么修。我的应用程序副本文件创建应用程序,然后将其导入到routes.py以及模型.py. 这个routes.py依靠模型.py对于我的用户类。我可以在本地运行它,它说Flask应用程序正在运行,但是我在浏览器中遇到404错误。在


Tags: 工具数据py模型github应用程序flaskhere
1条回答
网友
1楼 · 发布于 2024-05-01 22:05:58
if __name__ == "__main__":
    app.run(debug=True)

应该放在routes.py的末尾,而不是app.py。在

从这个answer读取:

When the Python interpreter reads a source file, it executes all of the code found in it.

Before executing the code, it will define a few special variables. For example, if the Python interpreter is running that module (the source file) as the main program, it sets the special __name__ variable to have a value __main__. If this file is being imported from another module, __name__ will be set to the module's name.

因此,只有当您运行app.py时,才会执行上面的代码。如果运行routes.py,它将变得毫无意义,除非它被放在routes.py模块中。在

我对它进行了测试,结果如期而至:

Index route

相关问题 更多 >