flask 启动后接受不到请求(postman: Could not get any response
There was an error connecting to http://...:...
代码结构:
server/
run.py
server/
__init__.py
log.py
views/
__init__.py
container.py
run.py:
from docker_server import app
if __name__ == '__main__':
app.run(port=8082, debug=True)
__init__.py under server dir:
from flask import Flask
app = Flask(__name__)
from server.views import container
app.register_blueprint(container.mod)
container.py:
mod = Blueprint('container', __name__, url_prefix='/container')
@mod.route("/", methods=['GET'])
def container_test():
logger.debug("container test")
return None
stackoverflow上也提过:
你在创建
mod
的时候指定了url_prefix='/container'
,访问的时候这样看看http://localhost:8082/container/
。而且使用蓝图的时候还要指定views
所在目录,官网的例子(如果指定,可能找不到这个蓝图):另外,蓝图推荐这样使用:
app/__init__/py
:app/your_blueprint/__init__.py
: