在alwaysdata.com部署Django [英] Deploying Django at alwaysdata.com

查看:78
本文介绍了在alwaysdata.com部署Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在django我尝试过这个,但我不能部署。我如何做

 #!/ 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。呃,我不会说法语,但它基本上是说:


  1. 在django项目的文件夹中创建名为 public 的目录。

  2. 在该目录中,创建文件 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)


  3. public 文件夹中创建一个.htaccess,具有以下内容:

      AddHandler fcgi d脚本.fcgi 
    RewriteEngine On
    RewriteCond%{REQUEST_FILENAME}!-f
    RewriteRule ^(。*)$ django.fcgi / $ 1 [QSA,L]


  4. 如果您打算添加django管理界面,请在中创建此符号链接公开目录:

      ln -s /usr/local/alwaysdata/python/django/1.1/ django / contrib / admin / media / media 


  5. 最后你的文件夹树层次结构应该以某种方式看起来像这样:

      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:

  1. Create a directory named public in the folder of your django project.
  2. 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")
    

  3. 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]
    

  4. 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
    

  5. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆