在 html 目录结构之外的某个位置创建 django 项目。例如,在 ~/code 中运行 django-admin 来创建 ~/code/yoursite
按照 Django 教程中所述的正常项目和数据库设置进行操作。
从虚拟 Python 环境中运行“pip install flup”。
在 ~/code 中创建以下脚本“django_cgi.py”(注意Python路径!):
#!~/your_new_env/bin/python
import sys, os
# Add a custom Python path for your project
sys.path.insert(0, "/must/be/full/path/to/code/yoursite")
# Set the DJANGO_SETTINGS_MODULE environment variable.
# This should match the name for the project you added to the path above
os.environ['DJANGO_SETTINGS_MODULE'] = 'yoursite.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
在 ~/html 内,使用以下某些变体创建或编辑 .htaccess 文件:
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/mysite.cgi
RewriteRule ^(.*)$ /mysite.cgi [QSA,L,PT]