Flask服务器已启动,但返回404

2024-06-14 04:57:29 发布

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

当我尝试使用“/”的路由运行我的应用程序时,它显示服务器正在运行,但当我转到它时,我得到了404。我在跟踪this tutorial

directory structure

microblog.py

from app import app

app/__init__.py

from flask import Flask
app = Flask(__name__)
from app import routes

app/routes.py

@app.route('/')
@app.route('/index')
def index():
    return 'Hello, World!'

在微博目录中,我执行:

set FLASK_APP=microblog.py
flask run
 * Serving Flask app "microblog.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

导航到http://127.0.0.1:5000/输出:

127.0.0.1 - - [27/Jan/2020 14:43:39] "GET / HTTP/1.1" 404 -

Tags: frompyimportapp应用程序httpflask路由