views:

803

answers:

2

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]
+5  A: 

Hi Emrah,

You are trying to mix two different web server integration methods: fcgi (fast cgi) and wsgi.

Your first snippet is for a wsgi interface with the web server and is the recommended method for integrating Django with Apache. Very good resources (including examples) to help you set this up correctly can be found in the official Django docs How to use Django with Apache and mod_wsgi and the mod_wsgi docs Integration with Django

The second snippet (with AddHandler line) is for fcgi. This is the kind of interface that is more typically used to interface Django with the lighttpd and nginx web servers. Resources for setting up fcgi interface can be found in official Django docs How to use Django with FastCGI, SCGI, or AJP.

Since it looks like alwaysdata.com only uses FastCGI (fcgi) interface you are stuck with this method. It looks like there are examples on their wiki page Déployer une application Django and particulary you'll need to replace your first (wsgi) snippet with this:

#!/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")
Van Gale
+6  A: 

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 symolic link in your public directory:

    ln -s /usr/local/alwaysdata/python/django/1.1/django/contrib/admin/media/ media
    
  5. In the end it should somehow 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.

Kenny M.
It worked!Congratulations on your first Django-powered page.thanks...
emrah sarı
Glad to hear that :)
Kenny M.
+1 for delivering an answer about a system with docs written in a language you don't speak. Maybe there should be a new badge for this, just not sure what it would be called. Multilingual-nontranslating-wild-ass-guess-hackage? Nah, too long. :-)
Peter Rowell
AlwaysData is becoming more and more international everyday. I think that they would be very happy if you are ready to help for the english Wiki (it's a wiki so you can contribute). If the documentation is in french, the support is worldclass :)
luc
Peter Rowell, great, but too long badge name *lol*, but it's not very difficult to translate documentation which is 80% code. You just need some common sense, I think ;) .luc, yes AlwaysData.com is a great free service and actually seems worth the money to upgrade the plan. The forum provides fast and high-class support and the variety of things you can do, *only* with the free plan, are amazing. I will contribute in the future.
Kenny M.