Flask加载app.py文件和不存在的页面。

huangapple go评论96阅读模式
英文:

flask loads app.py file and pages that no longer exist

问题

我在Windows上使用Flask进行开发。我使用python app.py加载Flask。而app.py包含以下代码:

  1. from flask import Flask
  2. app = Flask(__name)
  3. app.debug = True
  4. if __name__ == "__main__":
  5. app.run(debug=True)

然后,我尝试加载此页面http://127.0.0.1:5000/new_data_table,但它加载了一个页面,尽管不应该加载。以前,我在app.py中有这个页面,但我想要进行一些调试,但无论我运行app.py多少次,我所做的更改都不会反映出来。

我看到Flask似乎从app.py之外的某个地方加载了代码,可能是从某种缓存中。但我无法找到这样的东西或看到应该查找的地方。我需要知道Flask从哪里获取代码来加载页面。

当我在app.py中进行小改动时的输出:

  1. PS C:\Users\Documents\main> python app.py
  2. * Serving Flask app "app" (lazy loading)
  3. * Environment: production
  4. WARNING: This is a development server. Do not use it in a production deployment.
  5. Use a production WSGI server instead.
  6. * Debug mode: on
  7. * Restarting with watchdog (windowsapi)
  8. * Debugger is active!
  9. * Debugger PIN: 372-211-807
  10. * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  11. * Detected change in 'C:\\Users\\Documents\\main\\.ipynb_checkpoints\\app-checkpoint.py', reloading
  12. * Restarting with watchdog (windowsapi)
  13. * Debugger is active!
  14. * Debugger PIN: 372-211-807
  15. * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  16. * Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
  17. * Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
  18. * Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
  19. * Detected change in 'C:\\Users\\Documents\\main\\app.py', reloading
  20. * Detected change in 'C:\\Users\\Documents\\main\\app.py', reloading
  21. * Detected change in 'C:\\Users\\Documents\\main\\.~app.py', reloading
  22. * Restarting with watchdog (windowsapi)
  23. * Debugger is active!
  24. * Debugger PIN: 372-211-807
  25. * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

我查找了隐藏文件,但没有找到任何内容。我删除了ipynb-checkpoints和pycache文件夹等,但没有发现任何变化。

编辑:

运行flask routes的输出如下:

  1. Endpoint Methods Rule
  2. -------- ------- -----------------------
  3. static GET /static/<path:filename>
英文:

I was working with flask on windows. I load flask with python app.py. And app.py contains:

  1. from flask import Flask
  2. app = Flask(__name__)
  3. app.debug = True
  4. if __name__ == &quot;__main__&quot;:
  5. 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:

  1. PS C:\Users\Documents\main&gt; python app.py
  2. * Serving Flask app &quot;app&quot; (lazy loading)
  3. * Environment: production
  4. WARNING: This is a development server. Do not use it in a production deployment.
  5. Use a production WSGI server instead.
  6. * Debug mode: on
  7. * Restarting with watchdog (windowsapi)
  8. * Debugger is active!
  9. * Debugger PIN: 372-211-807
  10. * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  11. * Detected change in &#39;C:\\Users\\Documents\\main\\.ipynb_checkpoints\\app-checkpoint.py&#39;, reloading
  12. * Restarting with watchdog (windowsapi)
  13. * Debugger is active!
  14. * Debugger PIN: 372-211-807
  15. * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  16. * Detected change in &#39;C:\\Users\\Documents\\main\\.~app.py&#39;, reloading
  17. * Detected change in &#39;C:\\Users\\Documents\\main\\.~app.py&#39;, reloading
  18. * Detected change in &#39;C:\\Users\\Documents\\main\\.~app.py&#39;, reloading
  19. * Detected change in &#39;C:\\Users\\Documents\\main\\app.py&#39;, reloading
  20. * Detected change in &#39;C:\\Users\\Documents\\main\\app.py&#39;, reloading
  21. * Detected change in &#39;C:\\Users\\Documents\\main\\.~app.py&#39;, reloading
  22. * Restarting with watchdog (windowsapi)
  23. * Debugger is active!
  24. * Debugger PIN: 372-211-807
  25. * 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:

  1. Endpoint Methods Rule
  2. -------- ------- -----------------------
  3. static GET /static/&lt;path:filename&gt;

答案1

得分: 1

问题是,我们在日志中没有看到对本地主机的任何请求。 您可以通过以下方式使用Flask检查应用程序的所有路由:

  1. 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

huangapple
  • 本文由 发表于 2023年2月8日 13:53:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75381828.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定