英文:
flask loads app.py file and pages that no longer exist
问题
我在Windows上使用Flask进行开发。我使用python app.py
加载Flask。而app.py包含以下代码:
from flask import Flask
app = Flask(__name)
app.debug = True
if __name__ == "__main__":
app.run(debug=True)
然后,我尝试加载此页面http://127.0.0.1:5000/new_data_table
,但它加载了一个页面,尽管不应该加载。以前,我在app.py中有这个页面,但我想要进行一些调试,但无论我运行app.py多少次,我所做的更改都不会反映出来。
我看到Flask似乎从app.py之外的某个地方加载了代码,可能是从某种缓存中。但我无法找到这样的东西或看到应该查找的地方。我需要知道Flask从哪里获取代码来加载页面。
当我在app.py中进行小改动时的输出:
PS C:\Users\Documents\main> python app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with watchdog (windowsapi)
* Debugger is active!
* Debugger PIN: 372-211-807
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Detected change in 'C:\\Users\\Documents\\main\\.ipynb_checkpoints\\app-checkpoint.py', reloading
* Restarting with watchdog (windowsapi)
* Debugger is active!
* Debugger PIN: 372-211-807
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
* Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
* Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
* Detected change in 'C:\\Users\\Documents\\main\\app.py', reloading
* Detected change in 'C:\\Users\\Documents\\main\\app.py', reloading
* Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
* Restarting with watchdog (windowsapi)
* Debugger is active!
* Debugger PIN: 372-211-807
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
我查找了隐藏文件,但没有找到任何内容。我删除了ipynb-checkpoints和pycache文件夹等,但没有发现任何变化。
编辑:
运行flask routes
的输出如下:
Endpoint Methods Rule
-------- ------- -----------------------
static GET /static/<path:filename>
英文:
I was working with flask on windows. I load flask with python app.py
. And app.py contains:
from flask import Flask
app = Flask(__name__)
app.debug = True
if __name__ == "__main__":
app.run(debug=True)
Then I try to load this page http://127.0.0.1:5000/new_data_table
and it loads a page eventhough it shouldn't. I used to have this page in my app.py but I wanted to do some debugging but I see that the changes I make in app.py are not being reflected no matter how many times I re-run app.py.
What I see is that flask is loading the code from somewhere else than app.py, from some cache or something probably. But I am not able to find such things or see where to look for. I need to know where flask is getting the code to load the pages.
Output when I make small change in app.py:
PS C:\Users\Documents\main> python app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with watchdog (windowsapi)
* Debugger is active!
* Debugger PIN: 372-211-807
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Detected change in 'C:\\Users\\Documents\\main\\.ipynb_checkpoints\\app-checkpoint.py', reloading
* Restarting with watchdog (windowsapi)
* Debugger is active!
* Debugger PIN: 372-211-807
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
* Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
* Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
* Detected change in 'C:\\Users\\Documents\\main\\app.py', reloading
* Detected change in 'C:\\Users\\Documents\\main\\app.py', reloading
* Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
* Restarting with watchdog (windowsapi)
* Debugger is active!
* Debugger PIN: 372-211-807
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
I looked for hidden files, didn't find any. I deleted ipynb-checkpoints and pycache folders, etc.. but found no change.
Edit:
Output to flask routes
:
Endpoint Methods Rule
-------- ------- -----------------------
static GET /static/<path:filename>
答案1
得分: 1
问题是,我们在日志中没有看到对本地主机的任何请求。 您可以通过以下方式使用Flask检查应用程序的所有路由:
flask routes
英文:
The problem is, that we don't see any requests to localhost in your log. You can check all routes of your app via flask with:
flask routes
to see what routes are registered in your app
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论