在alwaysdata.com部署Django [英] Deploying Django at alwaysdata.com
问题描述
#!/ usr / bin / python
import sys
import os
base = os.path.dirname(os.path.abspath(__ file__))+'/ ..'
sys.path.append(base)
os .environ ['DJANGO_SETTINGS_MODULE'] ='myfirstapp.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
AddHandler fcgid-script .fcgi
选项+ FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(media /.*)$ - [L]
RewriteRule ^(adminmedia / 。*)$ - [L]
RewriteCond%{REQUEST_URI}!(cgi-bin / myproject.fcgi)
RewriteRule ^(。*)$ mysite.fcgi / $ 1 [L]
这是 alwaysdata wiki条目用于设置与fastcgi的Django。呃,我不会说法语,但它基本上是说:
- 在django项目的文件夹中创建名为
public
的目录。 -
在该目录中,创建文件
django.fcgi
,其中包含以下内容:#/ usr / bin / python
import os,sys
_PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__ file__) )
sys.path.insert(0,_PROJECT_DIR)
sys.path.insert(0,os.path.dirname(_PROJECT_DIR))
_PROJECT_NAME = _PROJECT_DIR.split ('/')[ - 1]
os.environ ['DJANGO_SETTINGS_MODULE'] =%s.settings%_PROJECT_NAME
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method =threaded,daemonize =false)
-
在
public
文件夹中创建一个.htaccess,具有以下内容:AddHandler fcgi d脚本.fcgi
RewriteEngine On
RewriteCond%{REQUEST_FILENAME}!-f
RewriteRule ^(。*)$ django.fcgi / $ 1 [QSA,L]
-
如果您打算添加django管理界面,请在
中创建此符号链接公开
目录:ln -s /usr/local/alwaysdata/python/django/1.1/ django / contrib / admin / media / media
-
最后你的文件夹树层次结构应该以某种方式看起来像这样:
myproject /
__init__.py
manage.py
public /
django.fcgi
.htaccess
media /
settings.py
urls.py
myapp /
views.py
models.py
希望这有帮助。我跟管理员说过,他说他很快就会提供一个英文的维基。让我们希望这将很快发生。
更新:有一个现在的英文维基文章
i new on django i tried this but i cant deploy. how can i do
#!/usr/bin/python
import sys
import os
base = os.path.dirname(os.path.abspath(__file__)) + '/..'
sys.path.append(base)
os.environ['DJANGO_SETTINGS_MODULE'] = 'myfirstapp.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
AddHandler fcgid-script .fcgi
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(adminmedia/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(cgi-bin/myproject.fcgi)
RewriteRule ^(.*)$ mysite.fcgi/$1 [L]
Here's the alwaysdata wiki entry for setting up Django with fastcgi. Only down-side: it's written in French.
Well, I don't speak French, but what it basically says is:
- Create a directory named
public
in the folder of your django project. In that directory create the file
django.fcgi
with the following content:#!/usr/bin/python import os, sys _PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, _PROJECT_DIR) sys.path.insert(0, os.path.dirname(_PROJECT_DIR)) _PROJECT_NAME = _PROJECT_DIR.split('/')[-1] os.environ['DJANGO_SETTINGS_MODULE'] = "%s.settings" % _PROJECT_NAME from django.core.servers.fastcgi import runfastcgi runfastcgi(method="threaded", daemonize="false")
Next, create a .htaccess in the
public
folder with the following content:AddHandler fcgid-script .fcgi RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]
If you're planning to include the django admin interface, create this symbolic link in your
public
directory:ln -s /usr/local/alwaysdata/python/django/1.1/django/contrib/admin/media/ media
In the end your folder tree hierarchy should somehow look like this:
myproject/ __init__.py manage.py public/ django.fcgi .htaccess media/ settings.py urls.py myapp/ views.py models.py
Hope this helps. I talked with the admin, and he said he will soon provide an English wiki. Let's hope this is going to happen anytime soon.
UPDATE: There is an English wiki article now.
这篇关于在alwaysdata.com部署Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!