flask.ext.script 建立的 manager 要怎么设定才能让外网访问呢?

2015-05-03 17:28:43 +08:00
 ca1n

使用flask-script建立manage.py进行操作,但是发现manage.run()的时候不能添加host参数,这样外网要怎么访问呢?

manager = Manager(app)是这样来的,试着用app.host = '0.0.0.0'这样设定失败了。。。

manager.run()里面添加host='0.0.0.0'这样设定也失败了。。

10890 次点击
所在节点    Flask
12 条回复
Septembers
2015-05-03 17:35:13 +08:00
nginx
taozle
2015-05-03 17:39:29 +08:00
python manager.py runserver help
ca1n
2015-05-03 17:39:58 +08:00
@Septembers 不调用flask.ext.script的时候直接run(host='0.0.0.0')就行了,manager里应该也有类似的方法阿
ca1n
2015-05-03 17:44:14 +08:00
@taozle 不行 runserver help这样报错了。。直接--help只返回了manager的可用参数,里面没有host和port。。
ca1n
2015-05-03 17:47:29 +08:00
而且runserver的help说明是这样的
runserver Runs the Flask development server i.e. app.run()
说调用了app.run()那为什么下面没用呢

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
app.host='0.0.0.0'
manager = Manager(app)
ca1n
2015-05-03 17:56:32 +08:00
grzhan
2015-05-03 17:58:22 +08:00
> python manage.py runserver --host 0.0.0.0
ca1n
2015-05-03 18:00:02 +08:00
@grzhan 谢了。。反应过来2L大概想说的是runserver --help
grzhan
2015-05-03 19:08:28 +08:00
@ca1n 我也是前两天刚好有一样的需求……
walle
2015-05-06 10:58:49 +08:00
使用nginx是正确的做法。
前几天也被这个困扰到,所以直接找到/usr/local/lib/python2.7/dist-packages/flask_script里面的commands.py文件把里面的host='127.0.0.1'改成host='0.0.0.0'。

当我把这个提交到github上去的时候,一个项目维护者给了我这么一段话。
Don't use the dev server for production. Use a real app and web server combo, such as uwsgi and nginx.

With this change, you make everyone expose their dev code in debug mode to anyone on the network by default, which is a bad idea.
ca1n
2015-05-07 16:18:24 +08:00
@walle 恩。。毕竟我只是做给我和女朋友玩儿的 所以也没有太多安全性的考虑暂时先能跑起来就行 不过还是谢了
ideaplat
2016-04-22 10:05:25 +08:00
./manage.py runserver -h '0.0.0.0'

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/188133

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX