flask manage.py runserver 无法传递参数

flask manage.py runserver can't pass parameter

user manager.py 运行server 我的 flask webframework 可以在 http://127.0.0.1:5000 上启动,但无法在网络中的其他计算机上访问。 所以我需要在网络中使用一个开放的IP。 虽然我使用波纹管命令:

manage.py runserver 192.168.49.25:8000

它不能运行并给出错误信息:

manage.py: error: unrecognized arguments: 192.168.49.25:8000

不知道怎么回事??

阅读 documentation:

Externally Visible Server If you run the server you will notice that the server is only accessible from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer.

If you have debug disabled or trust the users on your network, you can make the server publicly available simply by changing the call of the run() method to look like this:

app.run(host='0.0.0.0') This tells your operating system to listen on all public IPs.

如果您想使用 Flask-Script (python manage.py 运行server) 到 运行 您的 Flask 应用程序,您可以使用参数 --host 到 运行 它在 public IP 上。

python manage.py runserver --host 0.0.0.0 

另请参阅:https://flask-runner.readthedocs.org/en/latest/

如果您已经在使用 Flask-Script,那么您就有办法在您的代码中定义您的主机。

from yourapp import create_app
from flask_script import Manager, Server
from yourapp import config

app = create_app(config.DevelopmentConfig)
manager = Manager(app)

manager.add_command("runserver", Server(host=app.config['HOST'], port=app.config['PORT']))

if __name__ == '__main__':
    manager.run()

现在服务器主机和端口将来自配置