更新时间:2023-02-22 19:36:13
这些是为 Django 设置 Apache 需要执行的以下操作.我假设您在安装了 WAMP 服务器(32 位)的 Windows(32 位)上使用 Python 2.7(32 位).
These are the following things you need to do to setup Apache for Django. I assume you are using Python 2.7 (32-bit) on Windows (32-bit) with WAMP server (32-bits) installed.
下载 mod_wsgi-win32-ap22py27-3.3.so.或下载您各自的 .so 兼容文件
Download mod_wsgi-win32-ap22py27-3.3.so. Or download your respective .so compatible file
将其名称更改为 mod_wsgi.so
并将其复制到 Windows 上的 /Program Files/Apache Software Foundation/Apache22/modules
.
Change its name to mod_wsgi.so
and copy it to /Program Files/Apache Software Foundation/Apache22/modules
on Windows.
使用管理员权限打开 httpd.conf
.现在,您将找到带有 LoadModule ...
的行列表.只需将 LoadModule wsgi_module modules/mod_wsgi.so
添加到该列表中即可.
Open httpd.conf
using Admin rights. Now, you will find a list of lines with LoadModule ...
. Just add LoadModule wsgi_module modules/mod_wsgi.so
to that list.
你已经部分完成了..你可以重新启动apache,应该不会发现任何错误.
Your are partially done.. you can restart the apache and shouldn't find any errors.
现在您需要将其链接到您的 Django 项目.
Now you need to link it to your Django project.
在您的 Django 项目根文件夹中,添加 apache
文件夹并创建 django.wsgi
(不要更改此名称)和 apache_mydjango.conf代码>.
In your Django project root folder, add apache
folder and create django.wsgi
(don't change this name) and apache_mydjango.conf
.
在 httpd.conf
页面底部添加以下行.
In httpd.conf
add the following line at the bottom of the page.
包括d:/projects/mysite/apache_django_wsgi.conf"
打开 django.wsgi
并添加以下几行:
Open django.wsgi
and add the following lines:
import os, sys
sys.path.append('d:/projects/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
打开apache_djang_wsgi.conf
并添加:
Alias /images/ "d:/projects/mysite/templates/images/"
<Directory "d:/projects/mysite/images>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / "d:/projects/mysite/apache/django.wsgi"
<Directory "d:/projects/mysite/apache">
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot d:/projects/mysite
ServerName 127.0.0.1
</VirtualHost>
注意:
我假设您的 Django 项目层次结构是这样的:
I am assuming your Django project hierarchy is something like this:
mysite/
mysite/
settings.py
urls.py, wsgi.py.
manage.py
<apache> / apache_django_wsgi.conf, django.wsgi
***教程链接:
实际上我不明白为什么人们无法修复它.我在这里看到了很多问题,我什至发布了一些......所以,我想直接写一个初始设置版本作为答案