首页 > 解决方案 > Django - XAMPP - Apache - Cookiecutter

问题描述

我有一个使用 cookiecutter 配置的 Django 项目,我需要在 Windows 10 上使用 XAMPP 和带有 mod_wsgi 的 apache 部署项目。我已经尝试了一些解决方案,但对我不起作用。这是我的配置:

Apache/2.4.48 (Win64) OpenSSL/1.1.1k PHP/8.0.8 mod_wsgi/4.9.0 Python/3.7 Django 版本 3.2

wsgi.py

import os
import sys
from pathlib import Path

from django.core.wsgi import get_wsgi_application

ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent
sys.path.append(str(ROOT_DIR / "cinema"))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")

application = get_wsgi_application()

apache xampp 中的 httpd.conf


LoadFile "D:/Tools/Anaconda3/python37.dll"
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome "D:/Trabajo/ByT/CINEMA/venv"

WSGIPythonPath "D:/Trabajo/ByT/CINEMA/cinema/config/"
<VirtualHost *:80>
    ServerName localhost 
    WSGIPassAuthorization On
    ErrorLog "logs/cinema.error.log"
    CustomLog "logs/cinema.access.log" combined
    WSGIScriptAlias /cinema/ "D:/Trabajo/ByT/CINEMA/cinema/config/wsgi.py"

    <Directory "D:/Trabajo/ByT/CINEMA/cinema/config">
        <Files "wsgi.py">
            Order allow,deny
            Allow from all
            Require all granted
        </Files>
    </Directory>

    Alias /static "D:/Trabajo/ByT/CINEMA/cinema/staticfiles/"
    <Directory "D:/Trabajo/ByT/CINEMA/cinema/staticfiles/">
        Require all granted
    </Directory> 
    Alias /media "D:/Trabajo/ByT/CINEMA/cinema/media/"
    <Directory "D:/Trabajo/ByT/CINEMA/cinema/media/">
        Require all granted
    </Directory>  
</VirtualHost>

当我运行 apache 服务器时,我收到服务器错误 500,这是日志中的一个片段:

[Tue Nov 09 17:54:49.688418 2021] [wsgi:error] [pid 7892:tid 1980] [client ::1:19759] ModuleNotFoundError: No module named 'config'\r

标签: djangoapachexamppmod-wsgicookiecutter-django

解决方案


推荐阅读