我正在尝试使用Apache运行我的Django项目。
当我启动Apache时,我收到一个“内部服务器错误”,检查日志时,我发现它无法wsgi.py为我的项目执行www.example.com,并抛出下面的错误。
出现的错误是No module named 'localassets'
,即项目名称。
mod_wsgi (pid=5128): Failed to exec Python script file 'C:/Env/localassets/localassets/wsgi.py'., referer: http://localhost/
mod_wsgi (pid=5128): Exception occurred processing WSGI script 'C:/Env/localassets/localassets/wsgi.py'., referer: http://localhost/
Traceback (most recent call last):\r, referer: http://localhost/
File "C:/Env/localassets/localassets/wsgi.py", line 16, in <module>\r, referer: http://localhost/
application = get_wsgi_application()\r, referer: http://localhost/
File "C:\\Env\\Lib\\site-packages\\django\\core\\wsgi.py", line 12, in get_wsgi_application\r, referer: http://localhost/
django.setup(set_prefix=False)\r, referer: http://localhost/
File "C:\\Env\\Lib\\site-packages\\django\\__init__.py", line 19, in setup\r, referer: http://localhost/
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r, referer: http://localhost/
File "C:\\Env\\Lib\\site-packages\\django\\conf\\__init__.py", line 102, in __getattr__\r, referer: http://localhost/
self._setup(name)\r, referer: http://localhost/
File "C:\\Env\\Lib\\site-packages\\django\\conf\\__init__.py", line 89, in _setup\r, referer: http://localhost/
self._wrapped = Settings(settings_module)\r, referer: http://localhost/
File "C:\\Env\\Lib\\site-packages\\django\\conf\\__init__.py", line 217, in __init__\r, referer: http://localhost/
mod = importlib.import_module(self.SETTINGS_MODULE)\r, referer: http://localhost/
File "C:\\Program Files\\Python310\\Lib\\importlib\\__init__.py", line 126, in import_module\r, referer: http://localhost/
return _bootstrap._gcd_import(name[level:], package, level)\r, referer: http://localhost/
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import\r, referer: http://localhost/
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load\r, referer: http://localhost/
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked\r, referer: http://localhost/
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed\r, referer: http://localhost/
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import\r, referer: http://localhost/
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load\r, referer: http://localhost/
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked\r, referer: http://localhost/
ModuleNotFoundError: No module named 'localassets'\r, referer: http://localhost/
httpd.conf
LoadFile "C:/Program Files/Python310/python310.dll"
LoadModule wsgi_module "C:/Env/Lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
WSGIPythonHome "C:/Program Files/Python310"
WSGIScriptAlias / "C:/Env/localassets/localassets/wsgi.py"
WSGIPythonPath "C:/Env/Lib/site-packages"
<Directory "C:/Env/localassets/localassets/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static "C:/Env/localassets/localassets/static"
<Directory "C:/Env/localassets/localassets/static">
Require all granted
</Directory>
检查wsgi.py
文件,我也没有看到任何问题。
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'localassets.settings')
application = get_wsgi_application()
似乎我在wsgi.py
中缺少了一些东西,但我不确定我缺少了什么才能正确工作?
2条答案
按热度按时间ffscu2ro1#
在你的Python环境中,你必须安装这个库。您可以使用以下命令安装projectname:
pip install projectname
或pip3 install projectname
安装projectname python库后,
ModuleNotFoundError: No module named 'projectname'
错误将被解决。如果错误仍然存在,请检查您的
imports
-您可能必须从django_backend
或user_profile
导入gwbalxhn2#
只需将apps文件夹添加到www.example.com中的sys.pathwsgi.py:
顺便说一句。你似乎有虚拟环境文件夹与你的应用程序混合。我建议你分开