我是 Web 框架的新手,我使用 DJango-3.1.7 设计了小型网站。
我正在尝试在 Windows 10 平台的 Apache 服务器上部署 DJango 网站,但它似乎不正确或我错过了它。如果有人可以帮助解决这个问题,我们对我来说很宝贵。
我已经为这个应用程序配置了虚拟环境
问题:
获取错误 PYTHONHOME = (未设置) PYTHONPATH = (未设置)
error.log
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\Apache24\\bin\\httpd.exe'
sys.base_prefix = 'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python38'
sys.base_exec_prefix = 'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python38'
sys.executable = 'C:\\Apache24\\bin\\httpd.exe'
sys.prefix = 'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python38'
sys.exec_prefix = 'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python38'
sys.path = [
'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python38\\python38.zip',
'.\\DLLs',
'.\\lib',
'C:\\Apache24\\bin',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00002838 (most recent call first):
<no Python frame>
[Sat Jun 26 21:56:47.558067 2021] [mpm_winnt:crit] [pid 5344:tid 780] AH00419: master_main: create child process failed. Exiting.
etc/hosts
127.0.0.2 stack-hack.com
httpd.conf
LoadFile "c:/users/hp/appdata/local/programs/python/python38/python38.dll"
LoadModule wsgi_module "e:/Code-Stack/stack-hack/lib/site-packages/mod_wsgi/server/mod_wsgi.cp38-win_amd64.pyd"
WSGIPythonHome "e:/Code-Stack/stack-hack"
WSGIPythonPath "e:/Code-Stack/stack-hack/Lib/site-packages"
<VirtualHost *:80>
ServerAlias www.stack-hack.com
ServerName stack-hack.com
ServerAdmin info@admin.com
WSGIScriptAlias / "E:/Code-Stack/Stack-Hack/src/stackhack/wsgi.py"
<Directory "E:/Code-Stack/Stack-Hack/src/stackhack">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ "E:/Code-Stack/Stack-Hack/src/static/"
<Directory "E:/Code-Stack/Stack-Hack/src/static">
Require all granted
</Directory>
ErrorLog "E:/Code-Stack/Stack-Hack/logs/apache.error.log"
CustomLog "E:/Code-Stack/Stack-Hack/logs/apache.custom.log" common
</VirtualHost>
wsgi.py
import os
import sys
from django.core.wsgi import get_wsgi_application
from pathlib import Path
path_home = str(Path(__file__).parents[1])
if path_home not in sys.path:
sys.path.append(path_home)
os.environ['DJANGO_SETTINGS_MODULE'] = 'main.settings'
application = get_wsgi_application()
项目结构Stack-Hack [Virtual env]
- Lib
- Scripts
+ src
- home
- media
+ stackhack
- asgi.py
- settings.py
- urls.py
- wsgi.py
- static
- manage.py
- pyvenv.cfg
我做的解决方法:所有其他 django 设置都正常并且工作正常。我已经关注了各种博客文章来配置 Apache 服务器
最佳答案
尝试这个unset PYTHONPATH
unset PYTHONHOME
基于此 solution
关于python - Apache24 上的 DJango 部署不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68199691/