我正在嘗試配置兩個藍圖我的項目結構如下圖這是我所有的項目代碼init.pyfrom flask import Flaskapp = Flask(__name__)from mod_image.controllers import mod_image from mod_home.home import mod_home #the app config#app.config.from_object('config')#declaring image registration module/blueprint#from app.mod_image.controllers import mod_image as image_module# Register blueprint(s)app.register_blueprint(mod_home)app.register_blueprint(mod_image)if __name__ == "__main__": app.run()controllers.pyfrom flask import Blueprintmod_image = Blueprint('mod_image', __name__)@mod_image.route('/register')def register(): return "This is an example app"home.pyfrom flask import Blueprintmod_home = Blueprint('mod_home', __name__)@mod_home.route('/')def showHome(): return "This is a home"這是錯誤日志[Mon Jul 06 17:24:05.338680 2020] [wsgi:error] [pid 15407] [client ::1:38506] mod_wsgi (pid=15407): 無法執行 Python 腳本文件 '/var/www/wanasissmarteye/wanasissmarteye .wsgi'。[Mon Jul 06 17:24:05.338731 2020] [wsgi:error] [pid 15407] [client ::1:38506] mod_wsgi (pid=15407):處理 WSGI 腳本 '/var/www/wanasissmarteye/wanasissmarteye. wsgi'。[Mon Jul 06 17:24:05.338764 2020] [wsgi:error] [pid 15407] [client ::1:38506] Traceback(最后一次調用):[Mon Jul 06 17:24:05.338805 2020] [wsgi:error] [pid 15407] [client ::1:38506] 文件“/var/www/wanasissmarteye/wanasissmarteye.wsgi”,第 7 行,在[Mon Jul 06 17:24:05.338860 2020] [wsgi:error] [pid 15407] [client ::1:38506] from wanasissmarteye import app as application[Mon Jul 06 17:24:05.338889 2020] [wsgi:error] [pid 15407] [client ::1:38506] 文件“/var/www/wanasissmarteye/wanasissmarteye/init .py”,第 11 行,在[Mon Jul 06 17:24:05.339028 2020] [wsgi:error] [pid 15407] [client ::1:38506] from mod_home.home import mod_home[Mon Jul 06 17:24:05.339063 2020] [wsgi:error] [pid 15407] [client ::1:38506] ImportError: No module named mod_home.home
2 回答

largeQ
TA貢獻2039條經驗 獲得超8個贊
__init__.py
python 需要一個文件來將您的 mod_home 和 mod_image 識別為模塊并從中導入子模塊。
在要從中導入的每個文件夾的根目錄中添加一個。
請參閱此帖子:從不同文件夾導入文件

阿晨1998
TA貢獻2037條經驗 獲得超6個贊
好的,因為我是 Python 的新手。addind init .py 在我用谷歌搜索后解決了這個問題
init .py文件是使 Python 將目錄視為包含包所必需的;
添加回答
舉報
0/150
提交
取消