ca1n
V2EX  ›  Flask

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

  •  
  •   ca1n · May 3, 2015 · 12245 views
    This topic created in 4209 days ago, the information mentioned may be changed or developed.

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

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

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

    12 replies  •  2016-04-22 10:05:25 +08:00
    Septembers
    Septembers
    May 3, 2015 via Android
    1
    nginx
    taozle
    taozle
    May 3, 2015 via iPhone
    2
    python manager.py runserver help
    ca1n
    ca1n
    OP
    May 3, 2015
    3
    @Septembers 不调用flask.ext.script的时候直接run(host='0.0.0.0')就行了,manager里应该也有类似的方法阿
    ca1n
    ca1n
    OP
    May 3, 2015
    4
    @taozle 不行 runserver help这样报错了。。直接--help只返回了manager的可用参数,里面没有host和port。。
    ca1n
    ca1n
    OP
    May 3, 2015
    5
    而且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)
    grzhan
    grzhan
    May 3, 2015❤️2
    7
    > python manage.py runserver --host 0.0.0.0
    ca1n
    ca1n
    OP
    May 3, 2015
    8
    @grzhan 谢了。。反应过来2L大概想说的是runserver --help
    grzhan
    grzhan
    May 3, 2015
    9
    @ca1n 我也是前两天刚好有一样的需求……
    walle
    walle
    May 6, 2015
    10
    使用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
    ca1n
    OP
    May 7, 2015
    11
    @walle 恩。。毕竟我只是做给我和女朋友玩儿的 所以也没有太多安全性的考虑暂时先能跑起来就行 不过还是谢了
    ideaplat
    ideaplat
    Apr 22, 2016
    12
    ./manage.py runserver -h '0.0.0.0'
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2267 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 13:57 · PVG 21:57 · LAX 05:57 · JFK 08:57
    ♥ Do have faith in what you're doing.