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

时间:2020-01-27 14:01:24

标签: python flask

当我尝试使用“ /”路由运行我的应用程序时,它表明服务器正在运行,但是当我访问它时,我得到了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 -

1 个答案:

答案 0 :(得分:0)

此代码运行正常,您忘记在route.py中添加app

只需在from app import app中添加routes.py并根据教程运行该应用程序即可,