目前我正在嘗試在 PythonAnywhere 上部署我的第一個 FLASK 應(yīng)用程序。我不確定這是否是正確的術(shù)語,但我有一個文件夾作為模塊,因為我似乎無法找到部署我的應(yīng)用程序的正確方法。我什至不確定從哪里開始解決這個問題。有什么建議嗎?我的init .py 代碼是:import osfrom flask import Flaskdef create_app(test_config=None): # create and configure the app app = Flask(__name__, instance_relative_config=True) app.config.from_mapping( SECRET_KEY='secret', DATABASE=os.path.join(app.instance_path, 'LAMA.sqlite'), ) if test_config is None: # load the instance config, if it exists, when not testing app.config.from_pyfile('config.py', silent=True) else: # load the test config if passed in app.config.from_mapping(test_config) # ensure the instance folder exists try: os.makedirs(app.instance_path) except OSError: pass # database from . import db db.init_app(app) # authentication blueprint from . import auth app.register_blueprint(auth.bp) # blog blueprint - the main index # from . import blog # app.register_blueprint(blog.bp) # app.add_url_rule('/', endpoint='index') # book blueprint from . import book app.register_blueprint(book.bp) app.add_url_rule('/', endpoint='index') return app我還關(guān)注了 python 調(diào)試頁面,我已經(jīng)完成了以下操作:>>> import LAMA>>> print(LAMA)<module 'LAMA' from '/home/ivanv257/LAMA_MAIN/LAMA/__init__.py'>所以在我的 WSGI 配置文件的這個階段,我有:import syspath = '/home/ivanv257/LAMA_MAIN/LAMA/__init__.py'if path not in sys.path: sys.path.append(path)from LAMA import app as application我還嘗試了許多其他組合,例如path = '/home/ivanv257/LAMA_MAIN/LAMA/'from init import app as applicationpath = '/home/ivanv257/LAMA_MAIN/'from init import app as applicationpath = '/home/ivanv257/LAMA_MAIN/'from LAMA import app as application我的源代碼路徑是: /home/ivanv257/LAMA_MAIN/LAMA ,雖然我也嘗試過不同的組合,例如 /home/ivanv257/LAMA_MAIN/
2 回答

慕蓋茨4494581
TA貢獻(xiàn)1850條經(jīng)驗 獲得超11個贊
為了解決我的問題,我從 lama import create_app 更改了以下內(nèi)容(在一些幫助下):
import sys
path = '/home/ivanv257/LAMA_MAIN/LAMA'
if path not in sys.path:
sys.path.append(path)
from lama import create_app
application = create_app()
我還必須從 . 只進(jìn)口
import db
db.init_app(app)
# authentication blueprint
import auth
app.register_blueprint(auth.bp)
添加回答
舉報
0/150
提交
取消