楼主看的是flask web开发实践解析,现在到了部署阶段,因为先前用过helloflask上watchlist介绍的pythonanywhere部署,部署时遇到问题,打开部署网站的报错日志如下:
error.log
2023-11-19 07:54:16,271: Error running WSGI application
2023-11-19 07:54:16,273: ModuleNotFoundError: No module named 'wsgi'
2023-11-19 07:54:16,273: File "/var/www/jtping_pythonanywhere_com_wsgi.py", line 44, in <module>
2023-11-19 07:54:16,273: from wsgi import bp as application
2023-11-19 07:54:16,273: ***************************************************
2023-11-19 07:54:16,273: If you're seeing an import error and don't know why,
2023-11-19 07:54:16,274: we have a dedicated help page to help you debug:
2023-11-19 07:54:16,274: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-11-19 07:54:16,274: ***************************************************
2023-11-19 08:08:27,926: Error running WSGI application
2023-11-19 08:08:27,927: TypeError: 'Blueprint' object is not callable
2023-11-19 08:08:54,589: Error running WSGI application
2023-11-19 08:08:54,590: TypeError: 'Blueprint' object is not callable
2023-11-19 08:19:54,446: Error running WSGI application
2023-11-19 08:19:54,448: ModuleNotFoundError: No module named 'dotenv'
2023-11-19 08:19:54,448: File "/var/www/jtping_pythonanywhere_com_wsgi.py", line 44, in <module>
2023-11-19 08:19:54,450: we have a dedicated help page to help you debug:
2023-11-19 08:19:54,450: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-11-20 11:11:09,496: Error running WSGI application
2023-11-20 11:11:09,502: ModuleNotFoundError: No module named 'dotenv'
2023-11-20 11:11:09,502: File "/var/www/jtping_pythonanywhere_com_wsgi.py", line 44, in <module>
2023-11-20 11:11:09,502: from wsgi import bp as application
2023-11-20 11:11:09,503:
2023-11-20 11:11:09,503: File "/home/JTPing/microblog/./wsgi.py", line 3, in <module>
2023-11-20 11:11:09,503: from dotenv import load_dotenv
2023-11-20 11:11:09,503: ***************************************************
2023-11-20 11:11:09,503: If you're seeing an import error and don't know why,
2023-11-20 11:11:09,504: we have a dedicated help page to help you debug:
2023-11-20 11:11:09,504: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-11-20 11:11:09,504: ***************************************************
2023-11-20 11:11:10,446: Error running WSGI application
2023-11-20 11:11:10,447: ModuleNotFoundError: No module named 'dotenv'
2023-11-20 11:11:10,447: File "/var/www/jtping_pythonanywhere_com_wsgi.py", line 44, in <module>
2023-11-20 11:11:10,447: from wsgi import bp as application
2023-11-20 11:11:10,447:
2023-11-20 11:11:10,447: File "/home/JTPing/microblog/./wsgi.py", line 3, in <module>
2023-11-20 11:11:10,447: from dotenv import load_dotenv
2023-11-20 11:11:10,448: ***************************************************
2023-11-20 11:11:10,448: If you're seeing an import error and don't know why,
2023-11-20 11:11:10,448: we have a dedicated help page to help you debug:
2023-11-20 11:11:10,448: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-11-20 11:11:10,448: ***************************************************
2023-11-21 11:01:33,951: Error running WSGI application
2023-11-21 11:01:33,955: ModuleNotFoundError: No module named 'dotenv'
2023-11-21 11:01:33,955: File "/var/www/jtping_pythonanywhere_com_wsgi.py", line 44, in <module>
2023-11-21 11:01:33,955: from wsgi import bp as application
2023-11-21 11:01:33,955:
2023-11-21 11:01:33,955: File "/home/JTPing/microblog/./wsgi.py", line 3, in <module>
2023-11-21 11:01:33,955: from dotenv import load_dotenv
2023-11-21 11:01:33,955: ***************************************************
2023-11-21 11:01:33,956: If you're seeing an import error and don't know why,
2023-11-21 11:01:33,956: we have a dedicated help page to help you debug:
2023-11-21 11:01:33,956: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-11-21 11:01:33,956: ***************************************************
2023-11-21 11:01:38,492: Error running WSGI application
2023-11-21 11:01:38,493: ModuleNotFoundError: No module named 'dotenv'
2023-11-21 11:01:38,493: File "/var/www/jtping_pythonanywhere_com_wsgi.py", line 44, in <module>
2023-11-21 11:01:38,493: from wsgi import bp as application
2023-11-21 11:01:38,493:
2023-11-21 11:01:38,493: File "/home/JTPing/microblog/./wsgi.py", line 3, in <module>
2023-11-21 11:01:38,493: from dotenv import load_dotenv
2023-11-21 11:01:38,494: ***************************************************
2023-11-21 11:01:38,494: If you're seeing an import error and don't know why,
2023-11-21 11:01:38,494: we have a dedicated help page to help you debug:
2023-11-21 11:01:38,494: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-11-21 11:01:38,494: ***************************************************
2023-11-21 11:01:53,633: Error running WSGI application
2023-11-21 11:01:53,634: ModuleNotFoundError: No module named 'dotenv'
2023-11-21 11:01:53,634: File "/var/www/jtping_pythonanywhere_com_wsgi.py", line 44, in <module>
2023-11-21 11:01:53,635: from wsgi import bp as application
2023-11-21 11:01:53,635:
2023-11-21 11:01:53,635: File "/home/JTPing/microblog/./wsgi.py", line 3, in <module>
2023-11-21 11:01:53,635: from dotenv import load_dotenv
2023-11-21 11:01:53,635: ***************************************************
2023-11-21 11:01:53,636: If you're seeing an import error and don't know why,
2023-11-21 11:01:53,636: we have a dedicated help page to help you debug:
2023-11-21 11:01:53,636: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-11-21 11:01:53,636: ***************************************************
2023-11-21 11:02:21,901: Error running WSGI application
2023-11-21 11:02:21,902: ModuleNotFoundError: No module named 'dotenv'
2023-11-21 11:02:21,902: File "/var/www/jtping_pythonanywhere_com_wsgi.py", line 44, in <module>
2023-11-21 11:02:21,902: from wsgi import bp as application
2023-11-21 11:02:21,902:
2023-11-21 11:02:21,902: File "/home/JTPing/microblog/./wsgi.py", line 3, in <module>
2023-11-21 11:02:21,903: from dotenv import load_dotenv
2023-11-21 11:02:21,903: ***************************************************
2023-11-21 11:02:21,903: If you're seeing an import error and don't know why,
2023-11-21 11:02:21,903: we have a dedicated help page to help you debug:
2023-11-21 11:02:21,903: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-11-21 11:02:21,903: ***************************************************
但是楼主在pythonanywhere的bash console上python shell上试了下dotenv是存在的:
>>> from dotenv import load_dotenv
>>> import os
相关文件结构如下:
bluelog / wsgi.py
bluelog / app / main
wsgi.py:
import os
from dotenv import load_dotenv
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
if os.path.exists(dotenv_path):
load_dotenv(dotenv_path)
from app.main import bp
/var/www_my_domian_com_wsgi.py:
import sys
path = '/home/my_username/microblog'
if path not in sys.path:
sys.path.append(path)
from wsgi import bp as application