gpt4 book ai didi

python - flask 错误 : typeerror run() got an unexpected keyword argument 'host'

转载 作者:太空狗 更新时间:2023-10-30 01:34:39 24 4
gpt4 key购买 nike

我用 Flask 在 vi​​rtualbox 上建立了一个网站。该网站可以在本地主机上打开,但我无法通过端口转发打开它,所以我将代码从 manage.run() 更改为 manage.run(host='0.0.0.0' )

问题是我收到这个错误:

typeerror run() got an unexpected keyword argument 'host'. 

当将manage.run() 更改为manage.run(debug=True) 时会出现类似的错误。我只是遵循了 Flask 文档。 http://flask.pocoo.org/docs/quickstart/#a-minimal-application谁能告诉我为什么会收到此错误?

#!/usr/bin/env python
#-*- coding:utf-8 -*-

"""Manage Script."""

from sys import stderr, exit

from flask.ext.script import Manager, prompt_bool

from szupa import create_app
from szupa.extensions import db
from szupa.account.models import User
from szupa.context import create_category_db


app = create_app()
manager = Manager(app)


@manager.command
def initdb():
"""Initialize database."""
db.create_all()
create_category_db()


@manager.command
def migrate(created, action="up"):
module_name = "migrates.migrate%s" % created
try:
module = __import__(module_name, fromlist=["migrates"])
except ImportError:
print >> stderr, "The migrate script '%s' is not found." % module_name
exit(-1)
if prompt_bool("Confirm to execute migrate script '%s'" % module_name):
try:
action = getattr(module, action)
except AttributeError:
print >> stderr, "The given action '%s' is invalid." % action
exit(-1)
action(db)
print >> stderr, "Finished."


@manager.command
def dropdb():
"""Drop database."""
if prompt_bool("Confirm to drop all table from database"):
db.drop_all()


@manager.command
def setadmin(email):
"""Promote a user to administrator."""
user = User.query.filter_by(email=email).first()
if not user:
print >> stderr, "The user with email '%s' could not be found." % email
exit(-1)
else:
user.is_admin = True
db.session.commit()


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

最佳答案

正如@fangwz0577 在评论中所说,他们使用 manager.add_command 解决了这个问题。他们链接的存档版本是 here .

Next, create the manage.py file. Use this file to load additional Flask-scripts in the future. Flask-scripts provides a development server and shell:

from flask.ext.script import Manager, Serverfrom tumblelog import appmanager = Manager(app) # Turn on debugger by default and reloader manager.add_command("runserver", Server(    use_debugger = True,    use_reloader = True,    host = '0.0.0.0') )

关于python - flask 错误 : typeerror run() got an unexpected keyword argument 'host' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16195601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com