如何在共享主机中设置Django网站?我已经检查了Django的安装,一切正常。
>>> import django
>>> django.VERSION
>>> (1, 4, 0, 'final', 0)
我遵循了http://www.djangobook.com/en/2.0/chapter12/中关于在共享托管提供商上使用Apache运行Django的部分,但没有成功。目前网站是这样的
/home/django_projects/WebsiteName
/sites/WebsiteName.co.id/www/.htaccess
/sites/WebsiteName.co.id/www/dispatch.fcgi
.htaccess 文件长这样
AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ $1 [QSA,L]
RewriteRule ^(admin_media/.*)$ $1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]
而dispatch.fcgi的代码如下:
#!/usr/bin/python
import sys, os
sys.path = ['$HOME/lib/python/Django-1.4'] + sys.path
sys.path = ['$HOME/django_projects'] + sys.path
os.chdir("$HOME/django_projects")
#from flup.server.fcgi import WSGIServer
from django.core.servers.fastcgi import runfastcgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'WebsiteName.settings'
runfastcgi(["method=threaded", "daemonize=false"])
当我访问该网站时,它一直生成500错误,即内部错误。到目前为止,我尝试过以下方法:
[1] Changing AddHandler fastcgi-script .fcgi to AddHandler fcgid-script .fcgi
[2] Removing AddHandler fastcgi-script .fcgi
[3] Putting the website directory to /sites/WebsiteName.co.id/www/WebsiteName instead of /home/django_projects/WebsiteName/
[4] Do no. 3 and move dispatch.fcgi to /sites/WebsiteName.co.id/www/WebsiteName
如果我的问题很蠢,我很抱歉。我是 Django 的新手。顺便说一下,1-4 并不是按顺序的。这只是为了编号我尝试过的事情。另外,如果我选择了第四个,网站会显示 dispatch.fcgi 的内容。