Python 烧瓶蓝图404

Python 烧瓶蓝图404,python,flask,Python,Flask,我在尝试访问烧瓶蓝图中定义的路由时得到了404,我不明白为什么。有人知道我做错了什么吗(我对Flask和Python一般来说是新手,所以它可能是一些基本的东西) 我的蓝图(test.py): 我的app.py: from flask import Blueprint, jsonify, request from werkzeug.local import LocalProxy test_blueprint = Blueprint( 'test_blueprint', __name__,

我在尝试访问烧瓶蓝图中定义的路由时得到了404,我不明白为什么。有人知道我做错了什么吗(我对Flask和Python一般来说是新手,所以它可能是一些基本的东西)

我的蓝图(
test.py
):

我的
app.py

from flask import Blueprint, jsonify, request
from werkzeug.local import LocalProxy

test_blueprint = Blueprint(
    'test_blueprint', __name__, url_prefix='/test')


@test_blueprint.route('/test', methods=['GET'])
def get_all_tests():

    return jsonify([{
        "id": "1",
        "name": "Foo"
    }, {
        "id": "2",
        "name": "Bar"
    }, {
        "id": "3",
        "name": "Baz"
    }]), 200
from test import test_blueprint

from flask import abort, Flask
from os import environ


def create_app():

    app = Flask(__name__)

    app.config.from_object('config.settings')
    app.template_folder = app.config.get('TEMPLATE_FOLDER', 'templates')
    app.url_map.strict_slashes = False

    app.register_blueprint(test_blueprint)

    return app
点击
http://127.0.0.1:5000/test
是:

(venv) mymachine:api myusername$ python run.py
 * Restarting with stat
Starting server at 127.0.0.1 listening on port 5000 in DEBUG mode
 * Debugger is active!
 * Debugger PIN: 123-456-789
127.0.0.1 - - [2018-06-03 17:02:56] "GET /test HTTP/1.1" 404 342 0.012197
app.py
test.py
位于同一目录中,仅供参考


额外信息: 因为您可以在上面看到,我是从一个名为
run.py
的文件开始的,为了完整起见,这里是该文件:

from flask_failsafe import failsafe
from gevent import monkey
from gevent.pywsgi import WSGIServer
from werkzeug.debug import DebuggedApplication
from werkzeug.serving import run_with_reloader

@failsafe
def failsafe_app():
    from app import create_app
    return create_app()


app = failsafe_app()


@run_with_reloader
def run():

    app.debug = app.config['DEBUG']

    print('Starting server at %s listening on port %s %s' %
          (app.config['HOST'], app.config['PORT'], 'in DEBUG mode'
           if app.config['DEBUG'] else ''))

    if app.config['DEBUG']:
        http_server = WSGIServer((app.config['HOST'], app.config['PORT']),
                                 DebuggedApplication(app))
    else:
        if app.config['REQUEST_LOGGING']:
            http_server = WSGIServer((app.config['HOST'], app.config['PORT']),
                                     app)
        else:
            http_server = WSGIServer(
                (app.config['HOST'], app.config['PORT']), app, log=None)

    http_server.serve_forever()

您的端口号在url中的位置错误

它应该是
http://127.0.0.1:5000/test


正如您所看到的,您正在访问标准端口80,查找url
/test:5000

当您使用
url\u前缀定义蓝图时,此蓝图的每个规则都会将此前缀与给定路由连接起来


在您的示例中,url应该是
http://127.0.0.1:5000/test/test
访问视图
获取所有测试

。。。这只是我输入问题时的一个输入错误,对不起。我已将其更正为我实际使用的内容。您定义了一个
url\u prefix='/test'
,因此url应该是
http://127.0.0.1:5000/test/test
该死,我就知道这很简单。非常感谢。如果你回答这个问题,我可以接受你的修正@普尔穆鲁