返回信息流在用flask封装数据库web代理时,发现只要不注册blueprint,代理可以正常运行,浏览器输入localhost后能显示内容。一旦注册blueprint后再次运行,网页端就返回404,这是为啥,求解。
nginx和uwsgi的配置应该没啥问题?只要注释掉和blueprint相关代码后就能正常运行。
附上我的test.py
#--------------------------------------------------------------
from flask import Flask, request, json, abort, jsonify
from flask import Blueprint
mongo_blueprint = Blueprint("mongo_blueprint", __name__)
app=Flask(__name__)
@mongo_blueprint.route("/")
def hello():
return "-----*-----hello world-----*-----"
if __name__ == '__main__':
#app.register_blueprint(mongo_blueprint,url_prefix='mongo')
app.register_blueprint(mongo_blueprint)
app.run(host='0.0.0.0',port=8000,debug=True)
这是一条镜像帖。来源:北邮人论坛 / python / #12707同步于 2016/3/13
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
nginx+uwsgi+flask问题
solosseason
2016/3/13镜像同步17 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
试试把你的这行代码`app.register_blueprint(mongo_blueprint)`放到`app=Flask(__name__)`后面。。
【 在 fp544037857 的大作中提到: 】
: 试试把你的这行代码`app.register_blueprint(mongo_blueprint)`放到`app=Flask(__name__)`后面。。
先前有试过,还是不行。是不是blueprint对应的url不能简单写为localhost呢,郁闷
【 在 solosseason 的大作中提到: 】
: 先前有试过,还是不行。是不是blueprint对应的url不能简单写为localhost呢,郁闷
url_prefix='/mongo'这个呢?
【 在 fp544037857 的大作中提到: 】
:
: url_prefix='/mongo'这个呢?
这句我注释了啊,用了后curl localhost/mongo也没用
【 在 solosseason 的大作中提到: 】
: 这句我注释了啊,用了后curl localhost/mongo也没用
我的意思是加个/呢。。
我的习惯写法。。单看这几句感觉看不出什么来。。
也可能是我太久没有用Flask。。
【 在 fp544037857 的大作中提到: 】
:
: 我的意思是加个/呢。。
: 我的习惯写法。。单看这几句感觉看不出什么来。。
: ...................
刚刚试了一下,还是不可以的,我现在很怀疑是不是我搭建的环境出现了问题,无法理解
这段单文件没有问题。可以预期执行。uwsigi的问题。。我比较水。。你问上面这个学姐好了。。
from flask import Flask
from flask import Blueprint
app = Flask(__name__)
mongo_blueprint = Blueprint("mongo_blueprint", __name__)
@mongo_blueprint.route("/")
def hello():
return "-----*-----hello world-----*-----"
if __name__ == '__main__':
app.register_blueprint(mongo_blueprint, url_prefix='/mongo')
app.run()
【 在 solosseason 的大作中提到: 】
: 在用flask封装数据库web代理时,发现只要不注册blueprint,代理可以正常运行,浏览器输入localhost后能显示内容。一旦注册blueprint后再次运行,网页端就返回404,这是为啥,求解。
: nginx和uwsgi的配置应该没啥问题?只要注释掉和blueprint相关代码后就能正常运行。
: 附上我的test.py
: ...................