You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flask应用部署后无法访问localhost:5000问题求助

Troubleshooting Flask 404 Error When Accessing Localhost

Let’s work through why your Flask app is throwing a "Not Found" error even though the server seems to be running. Here are practical steps to diagnose and fix the issue:

Possible Causes & Fixes

  • Confirm your code is saved and executing correctly
    The runfile output shows it’s loading flask_1.py, but IDEs like Spyder sometimes fail to pick up unsaved changes. Double-check that your code is saved, and ensure the @app.route('/') decorator is properly attached to the index() function—no typos or extra spaces in the route string. Your code looks correct on paper, but a missing save could mean the server is running an older version of the file.

  • Verify the server is running on port 5000
    Flask defaults to port 5000, but if that port is already in use, it will automatically switch to another (like 5001). Look closely at your server output: does it explicitly state * Running on http://0.0.0.0:5000/? If it’s using a different port, update your URL to match (e.g., http://localhost:5001/).

  • Ensure you’re accessing the exact root route
    Your route is set to /, so try accessing both http://localhost:5000/ and http://localhost:5000 (the trailing slash is optional in Flask, but some browsers or proxies can mangle requests). Test in incognito mode to rule out cache or browser extension interference.

  • Run the app directly from the terminal
    IDE-specific run commands like runfile can sometimes introduce unexpected behavior. Open a command prompt, navigate to your project directory:

    cd C:/Users/RB287JD/Documents/Programs
    

    Then run the script directly:

    python flask_1.py
    

    This bypasses any IDE quirks and ensures your code is loaded as intended.

  • Check for route conflicts
    Make sure there’s no other code in flask_1.py that overrides the / route later. If you have another @app.route('/') decorator on a different function, it will replace your index() route, leading to a 404 if that function isn’t working as expected.


内容的提问来源于stack exchange,提问作者dhinar1991

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:54:16