windows+apache+mod_python configure the django run environment

  • 2020-05-06 12:04:26
  • OfStack

1. Create mysite test site: django-admin.py startproject mysite

2. Create a test page: hello.py, which reads as follows:

from django.http import HttpResponse

def index(request):
return HttpResponse('Hello, Django!')


3. Create the mod_py_dj.conf configuration file, which reads as follows:

LoadModule python_module modules/mod_python_so.pyd

Listen 8081
NameVirtualHost *:8081
< VirtualHost *:8081 >
< Location "/" >
SetHandler python-program
PythonPath "['d:\open\www'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonAutoReload Off
PythonDebug On
< /Location >
< /VirtualHost >

Note: in this VirtualHost, you do not need to configure DocumentRoot, otherwise add the following:

< Directory "d:\open\www" >
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
< /Directory >

No DocumentRoot configuration, less configuration.


4. Modify the url.py file and add one line:

(r'^hello/$', 'mysite.hello.index')


5, test, http: / / localhost: 8081 / hello /

Related articles: