python - Apache24 上的 DJango 部署不起作用

标签 python django apache virtualenv virtualhost

我是 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 服务器
  • https://montesariel.com/blog/post-3
  • https://www.codementor.io/@aswinmurugesh/deploying-a-django-application-in-windows-with-apache-and-mod_wsgi-uhl2xq09e
  • 最佳答案

    尝试这个unset PYTHONPATHunset PYTHONHOME基于此 solution

    关于python - Apache24 上的 DJango 部署不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68199691/

    相关文章:

    python - 在我的听众中如何检查是否设置了 dryrun 标志

    javascript - 为什么我的 Web 应用程序在多次 GET 请求后崩溃?

    python - 有没有可以在 Excel 中生成图表的 Python 库?

    python - 如何使 django 全局可用

    php - 如何在 Apache (Windows) 中保护我的 PHP 应用程序文件夹?

    php - 在 MySQL 查询中使用 GET 变量是否安全?

    python - 使用 pandas df 旋转 sns 热图

    python - 在 Django 中自动更新个人资料图片

    jquery - 创建与 CSS/HTML 相关的丰富动态单页 Django Web 应用程序的最佳方法

    wordpress - 如何制作 www.mywebsite.com/blog?