运行我的应用程序时使用 python manage.py run -h 0.0.0.0
很好用。
这就是 manage.py
我用来创建 flask 组的文件。
from flask.cli import FlaskGroup
from myapp import create_app
# create a flask app
app = create_app()
cli = FlaskGroup(create_app=create_app)
if __name__ == '__main__':
cli()
我的 __init__.py
将create\u app函数传递给flaskgroup的文件:
from flask import Flask
def create_app():
"""Create a Flask application
Returns:
Flask: the Flask application
"""
# instantiate the app
app = Flask(__name__)
# register blueprints
from myapp.views import main_blueprint
app.register_blueprint(main_blueprint)
# shell context for flask cli
app.shell_context_processor({"app": app})
return app
如果我试着用gunicorn wsgi.py
文件:
from manage import cli
if __name__ == '__main__':
cli.run()
那就跑吧 gunicorn
然后提出请求,我得到这个错误,我不知道如何解决。
gunicorn --bind=0.0.0.0:5000 wsgi:cli ──(Thu,Apr08)─┘
[2021-04-08 09:29:14 -0700] [28441] [INFO] Starting gunicorn 20.1.0
[2021-04-08 09:29:14 -0700] [28441] [INFO] Listening at: http://0.0.0.0:5000 (28441)
[2021-04-08 09:29:14 -0700] [28441] [INFO] Using worker: sync
[2021-04-08 09:29:14 -0700] [28442] [INFO] Booting worker with pid: 28442
[2021-04-08 09:29:17 -0700] [28442] [ERROR] Error handling request /tasks
Traceback (most recent call last):
File "/Users/me/Library/Caches/pypoetry/virtualenvs/myapp-6qIUXtyt-py3.9/lib/python3.9/site-packages/gunicorn/workers/sync.py", line 136, in handle
self.handle_request(listener, req, client, addr)
File "/Users/me/Library/Caches/pypoetry/virtualenvs/myapp-6qIUXtyt-py3.9/lib/python3.9/site-packages/gunicorn/workers/sync.py", line 179, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/Users/me/Library/Caches/pypoetry/virtualenvs/myapp-6qIUXtyt-py3.9/lib/python3.9/site-packages/click/core.py", line 829, in __call__
return self.main(*args,**kwargs)
File "/Users/me/Library/Caches/pypoetry/virtualenvs/myapp-6qIUXtyt-py3.9/lib/python3.9/site-packages/flask/cli.py", line 586, in main
return super(FlaskGroup, self).main(*args,**kwargs)
File "/Users/me/Library/Caches/pypoetry/virtualenvs/myapp-6qIUXtyt-py3.9/lib/python3.9/site-packages/click/core.py", line 777, in main
_bashcomplete(self, prog_name, complete_var)
File "/Users/me/Library/Caches/pypoetry/virtualenvs/myapp-6qIUXtyt-py3.9/lib/python3.9/site-packages/click/core.py", line 65, in _bashcomplete
complete_var = "_{}_COMPLETE".format(prog_name.replace("-", "_").upper())
AttributeError: 'function' object has no attribute 'replace'
对这个错误的帮助将是巨大的。谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!