V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ca1n
V2EX  ›  Flask

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

  •  
  •   ca1n · 2015-05-03 17:28:43 +08:00 · 10865 次点击
    这是一个创建于 3252 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    12 条回复    2016-04-22 10:05:25 +08:00
    Septembers
        1
    Septembers  
       2015-05-03 17:35:13 +08:00 via Android
    nginx
    taozle
        2
    taozle  
       2015-05-03 17:39:29 +08:00 via iPhone
    python manager.py runserver help
    ca1n
        3
    ca1n  
    OP
       2015-05-03 17:39:58 +08:00
    @Septembers 不调用flask.ext.script的时候直接run(host='0.0.0.0')就行了,manager里应该也有类似的方法阿
    ca1n
        4
    ca1n  
    OP
       2015-05-03 17:44:14 +08:00
    @taozle 不行 runserver help这样报错了。。直接--help只返回了manager的可用参数,里面没有host和port。。
    ca1n
        5
    ca1n  
    OP
       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
        6
    ca1n  
    OP
       2015-05-03 17:56:32 +08:00
    grzhan
        7
    grzhan  
       2015-05-03 17:58:22 +08:00   ❤️ 2
    > python manage.py runserver --host 0.0.0.0
    ca1n
        8
    ca1n  
    OP
       2015-05-03 18:00:02 +08:00
    @grzhan 谢了。。反应过来2L大概想说的是runserver --help
    grzhan
        9
    grzhan  
       2015-05-03 19:08:28 +08:00
    @ca1n 我也是前两天刚好有一样的需求……
    walle
        10
    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
        11
    ca1n  
    OP
       2015-05-07 16:18:24 +08:00
    @walle 恩。。毕竟我只是做给我和女朋友玩儿的 所以也没有太多安全性的考虑暂时先能跑起来就行 不过还是谢了
    ideaplat
        12
    ideaplat  
       2016-04-22 10:05:25 +08:00
    ./manage.py runserver -h '0.0.0.0'
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3207 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 11:35 · PVG 19:35 · LAX 04:35 · JFK 07:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.