: HOWTODjangoFastCGI

Welcome :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Most recent edit on 2008-06-19 14:51:30 by AlessandroGuido

No differences.


Edited on 2008-06-19 14:50:25 by AlessandroGuido

Additions:

Using Django on ASO with FastCGI

Installing django

Testing FastCGI

Setup django dispatcher

URL rewriting rules

Admin media



Deletions:

Installing django

Testing FastCGI

Setup django dispatcher

URL rewriting rules

Admin media





Edited on 2008-06-19 14:49:25 by AlessandroGuido

Additions:

Installing django

Testing FastCGI

Setup django dispatcher

URL rewriting rules





Edited on 2008-06-19 06:55:41 by AlessandroGuido

Additions:

Admin media

To get a working admin site I did the following:
Edit myproject/settings.py
ADMIN_MEDIA = '/admin_media/'
and
$ cd ~/public_html
$ ln -s ../local/lib/python2.4/site-packages/django/contrib/admin/media admin_media
However, for a tiny account, you should try to get media files from another host


Deletions:
That's all folks! Enjoy your django ;)



Edited on 2008-06-19 06:38:23 by AlessandroGuido

Additions:
I've managed to get django working on my tiny account, mostly following this document.
Firstly we download the latest django code from its svn and install in our home directory
$ mkdir /tmp/$USER
$ cd /tmp/$USER
$ svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk
$ cd django-trunk
$ python setup.py install --prefix $HOME/local
Then we need to set up some environment variables: add theese two lines at the bottom of $HOME/.bash_profile with your favourite editor
export PYTHONPATH="$PYTHONPATH:$HOME/local/lib/python2.4/site-packages"
export PATH="$PATH:$HOME/local/bin"
and then check
$ source $HOME/.bash_profile
$ echo $PYTHONPATH
Then we need an additional package called "flup" to get fastcgi working
$ cd /tmp/$USER
$ wget http://www.saddi.com/software/flup/dist/flup-1.0.tar.gz
$ tar xzf flup-1.0.tar.gz
$ cd flup-1.0
$ cp -r flup $HOME/local/lib/python2.4/site-packages
We can now remove temporary files
$ cd $HOME
$ rm -ri /tmp/$USER
To test if flup is working create ~/public_html/hello.fcgi with the following content
#!/bin/env python
sys.path += ['/home/MYUSER/local/lib/python2.4/site-packages']
from flup.server.fcgi import WSGIServer
def test_app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
yield 'Hello, world!\n'
WSGIServer(test_app).run()
Make it executable and run it from the commandline:
$ chmod 755 ~/public_html/hello.fcgi
$ ~/public_html/hello.fcgi
and you should see "Hello, World!" in the output. Then try to reach it with your browser.
If fastcgi is working, then we can procede with setting up our django project:
$ cd $HOME
$ mkdir django-projects
$ cd django-projects
$ django-admin.py startproject myproject
$ cd myproject
... edit settings.py ...
$ python manage.py syncdb
A dispatcher is needed to get django working. Create a new file ~/public_html/myproject.fcgi
#!/bin/env python
import sys, os
sys.path += ['/home/MYUSER/local/lib/python2.4/site-packages']
sys.path += ['/home/MYUSER/django-projects']
# Switch to the directory of your project. (Optional.)
# os.chdir("/home/MYUSER/django-projects/myproject")
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
give it right permissions and test
$ chmod 755 ~/public_html/myproject.fcgi
$ ~/public_html/myproject.fcgi
You should now be able to reach it through yout broser at http://mydomain/myproject.fcgi
The next thing to do is to setup rewrite rules to get better urls
edit your ~/public_html/.htaccess (this will work if you have only one project)
RewriteEngine On
RewriteRule ^(.*)$ myproject.fcgi/$1 [QSA,L]
If you have more projects try the following (untested)
RewriteEngine On
RewriteRule ^myproject/(.*)$ myproject.fcgi/$1 [QSA,L]
RewriteRule ^otherproject/(.*)$ otherproject.fcgi/$1 [QSA,L]
And you should be able to reach your sites with http://mydomain/myproject/ and http://mydomain/otherprojects/
Obviously you have to create the otherproject.fcgi dispatcher
That's all folks! Enjoy your django ;)


Deletions:

Note: This information may be out of date. If you have experience with Django FastCGI support, please provide an update

I almost have Django working on my tiny shared account. Actually, I think it works right, but I don't have the rewrite rules correct and that's causing the problem. Anyway, I'll step you through what I have so far.
First of all, you need to make sure you have Python2.3 for FCGI (and I think Django) to work. For more details about getting fcgi working, see this thread. You also need to have shell access. If you don't, submit a ticket to ASO support.
First, open your shell and confirm your version of Python (be sure to use a Capital V):
-jailshell-2.05b$ python -V
Python 2.3.4
If you have anything prior to 2.3.x you'll have to see about getting your server upgraded. (I'm told the new servers are at 2.3.x while the old are 2.2.x - if you just signed up for a new account, you should be good)
Ok, assuming your on one of the new servers, it's time to get started. Although Django is now offered both as a tarball and from svn, I chose to install from subversion as its easier to update to latest trunk etc. In your shell, make sure you're in your HOME dir and do:
cd ~
svn co http://code.djangoproject.com/svn/django/trunk/ django_src
Run the following commands: (so that Django is available from your shell)
export PATH=$PATH:$HOME/django_src/django/bin
export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects
Then add them to your .bash_profile file. Save the file, upload it and then continue with these instructions.
Create a Django projects directory and create your first Django project.
mkdir django_projects
cd django_projects
django-admin.py startproject myproject
If you don't want other users on your shared host to have access to your DB settings, change the permissions on your myproject.settings file so that ONLY YOUR USER can read them.  
chmod 600 myproject/settings.py
Edit the myproject.settings (myproject/settings.py) file to add your database connection parameters.
Initialize the database.
manage.py syncdb
Now its time to create the publicly available directory. Whether you set that up as a sub domain through CPanel or just create a sub-dir under ~/public_html (which you can always point to with a sub domain of the same name later) is your choice. For this exersize, we'll assume your just creating a sub-dir, which needs to have the [[http://svn.saddi.com/py-lib/trunk/fcgi.py fcgi.py]] script.
cd ~/www
mkdir myproject
cd myproject
wget http://svn.saddi.com/py-lib/trunk/fcgi.py
chmod 755 fcgi.py
Now you need to create a file named django.fcgi in the same dir, which should contain the following (replace 'username' with your username on lines 3 and 4 and 'myproject' with the name of your project if it differs from the example used above):
(python)
#!/usr/bin/env python
sys.path += ['/home/username/django_src']
sys.path += ['/home/username/django_projects']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
WSGIServer(WSGIHandler()).run()
Set the correct permissions on django.fcgi. Also, you must ensure django.fcgi uses Unix line endings in order for FastCGI to work.
chmod 755 django.fcgi

At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/. (Note: It usually takes a while for FastCGI to get ready and actually work. So, just let it sit on your server and keep on trying to access is it--because, for most people, it won't load on the first try.)
If you wish to pass everything in myproject dir through fast-cgi add the following to your .htaccess file within ~/www/myproject
%%RewriteEngine On
RewriteRule ^(.*)$ django.fcgi/myproject/$1 [QSA,L]
If you use the native admin goodness in django, you'll want to create a symbolic link to the admin media files so that your CSS and whatnot works correctly. Here's how:
cd ~/www
ln -s ~/django_src/django/contrib/admin/media media




Edited on 2007-09-27 23:57:37 by TimDorr

Additions:

Note: This information may be out of date. If you have experience with Django FastCGI support, please provide an update





Edited on 2007-08-09 11:55:24 by ShadyTrees [Unix line endings on django.fcgi]

Additions:
Set the correct permissions on django.fcgi. Also, you must ensure django.fcgi uses Unix line endings in order for FastCGI to work.

Deletions:
Set the correct permissions on django.fcgi.



Edited on 2007-07-07 23:36:05 by ScottNS [Fixed modification to .htaccess so admin feature will work]

Additions:
RewriteRule ^(.*)$ django.fcgi/myproject/$1 [QSA,L]

Deletions:
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]



Edited on 2007-06-29 01:52:49 by NateRitter [added the symbolic link for admin media]

Additions:
If you use the native admin goodness in django, you'll want to create a symbolic link to the admin media files so that your CSS and whatnot works correctly. Here's how: ln -s ~/django_src/django/contrib/admin/media media



Edited on 2007-06-28 22:29:06 by NateRitter [changed first line of the django.fcgi file to be environment general]

Additions:
I almost have Django working on my tiny shared account. Actually, I think it works right, but I don't have the rewrite rules correct and that's causing the problem. Anyway, I'll step you through what I have so far.
First of all, you need to make sure you have Python2.3 for FCGI (and I think Django) to work. For more details about getting fcgi working, see this thread. You also need to have shell access. If you don't, submit a ticket to ASO support.
First, open your shell and confirm your version of Python (be sure to use a Capital V):
-jailshell-2.05b$ python -V
Python 2.3.4

If you have anything prior to 2.3.x you'll have to see about getting your server upgraded. (I'm told the new servers are at 2.3.x while the old are 2.2.x - if you just signed up for a new account, you should be good)
Ok, assuming your on one of the new servers, it's time to get started. Although Django is now offered both as a tarball and from svn, I chose to install from subversion as its easier to update to latest trunk etc. In your shell, make sure you're in your HOME dir and do:
cd ~
svn co http://code.djangoproject.com/svn/django/trunk/ django_src

Run the following commands: (so that Django is available from your shell)
export PATH=$PATH:$HOME/django_src/django/bin
export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects

Then add them to your .bash_profile file. Save the file, upload it and then continue with these instructions.
Create a Django projects directory and create your first Django project.
mkdir django_projects
cd django_projects
django-admin.py startproject myproject

If you don't want other users on your shared host to have access to your DB settings, change the permissions on your myproject.settings file so that ONLY YOUR USER can read them.
chmod 600 myproject/settings.py

Edit the myproject.settings (myproject/settings.py) file to add your database connection parameters.
Initialize the database.
manage.py syncdb

Now its time to create the publicly available directory. Whether you set that up as a sub domain through CPanel or just create a sub-dir under ~/public_html (which you can always point to with a sub domain of the same name later) is your choice. For this exersize, we'll assume your just creating a sub-dir, which needs to have the fcgi.py script.
cd ~/www
mkdir myproject
cd myproject
wget http://svn.saddi.com/py-lib/trunk/fcgi.py
chmod 755 fcgi.py

Now you need to create a file named django.fcgi in the same dir, which should contain the following (replace 'username' with your username on lines 3 and 4 and 'myproject' with the name of your project if it differs from the example used above):
#!/usr/bin/env python
import sys
sys.path += ['/home/username/django_src']
sys.path += ['/home/username/django_projects']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
WSGIServer(WSGIHandler()).run()

Set the correct permissions on django.fcgi.
chmod 755 django.fcgi

At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/. (Note: It usually takes a while for FastCGI to get ready and actually work. So, just let it sit on your server and keep on trying to access is it--because, for most people, it won't load on the first try.)
If you wish to pass everything in myproject dir through fast-cgi add the following to your .htaccess file within ~/www/myproject
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]


Deletions:
I almost have Django working on my tiny shared account. Actually, I think it works right, but I don't have the rewrite rules correct and that's causing the problem. Anyway, I'll step you through what I have so far.

First of all, you need to make sure you have Python2.3 for FCGI (and I think Django) to work. For more details about getting fcgi working, see this thread. You also need to have shell access. If you don't, submit a ticket to ASO support.

First, open your shell and confirm your version of Python (be sure to use a Capital V):

-jailshell-2.05b$ python -V
Python 2.3.4


If you have anything prior to 2.3.x you'll have to see about getting your server upgraded. (I'm told the new servers are at 2.3.x while the old are 2.2.x - if you just signed up for a new account, you should be good)

Ok, assuming your on one of the new servers, it's time to get started. Although Django is now offered both as a tarball and from svn, I chose to install from subversion as its easier to update to latest trunk etc. In your shell, make sure you're in your HOME dir and do:

cd ~
svn co http://code.djangoproject.com/svn/django/trunk/ django_src


Run the following commands: (so that Django is available from your shell)

export PATH=$PATH:$HOME/django_src/django/bin
export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects


Then add them to your .bash_profile file. Save the file, upload it and then continue with these instructions.

Create a Django projects directory and create your first Django project.

mkdir django_projects
cd django_projects
django-admin.py startproject myproject


If you don't want other users on your shared host to have access to your DB settings, change the permissions on your myproject.settings file so that ONLY YOUR USER can read them.

chmod 600 myproject/settings.py


Edit the myproject.settings (myproject/settings.py) file to add your database connection parameters.

Initialize the database.

manage.py syncdb


Now its time to create the publicly available directory. Whether you set that up as a sub domain through CPanel or just create a sub-dir under ~/public_html (which you can always point to with a sub domain of the same name later) is your choice. For this exersize, we'll assume your just creating a sub-dir, which needs to have the fcgi.py script.

cd ~/www
mkdir myproject
cd myproject
wget http://svn.saddi.com/py-lib/trunk/fcgi.py
chmod 755 fcgi.py


Now you need to create a file named django.fcgi in the same dir, which should contain the following (replace 'username' with your username on lines 3 and 4 and 'myproject' with the name of your project if it differs from the example used above):

#!/usr/bin/python
import sys
sys.path += ['/home/username/django_src']
sys.path += ['/home/username/django_projects']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
WSGIServer(WSGIHandler()).run()


Set the correct permissions on django.fcgi.

chmod 755 django.fcgi


At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/. (Note: It usually takes a while for FastCGI to get ready and actually work. So, just let it sit on your server and keep on trying to access is it--because, for most people, it won't load on the first try.)

If you wish to pass everything in myproject dir through fast-cgi add the following to your .htaccess file within ~/www/myproject
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]




Edited on 2007-02-12 18:40:15 by CollinGrady

Additions:
I almost have Django working on my tiny shared account. Actually, I think it works right, but I don't have the rewrite rules correct and that's causing the problem. Anyway, I'll step you through what I have so far.

First of all, you need to make sure you have Python2.3 for FCGI (and I think Django) to work. For more details about getting fcgi working, see this thread. You also need to have shell access. If you don't, submit a ticket to ASO support.

First, open your shell and confirm your version of Python (be sure to use a Capital V):

-jailshell-2.05b$ python -V
Python 2.3.4


If you have anything prior to 2.3.x you'll have to see about getting your server upgraded. (I'm told the new servers are at 2.3.x while the old are 2.2.x - if you just signed up for a new account, you should be good)

Ok, assuming your on one of the new servers, it's time to get started. Although Django is now offered both as a tarball and from svn, I chose to install from subversion as its easier to update to latest trunk etc. In your shell, make sure you're in your HOME dir and do:

cd ~
svn co http://code.djangoproject.com/svn/django/trunk/ django_src


Run the following commands: (so that Django is available from your shell)

export PATH=$PATH:$HOME/django_src/django/bin
export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects


Then add them to your .bash_profile file. Save the file, upload it and then continue with these instructions.

Create a Django projects directory and create your first Django project.

mkdir django_projects
cd django_projects
django-admin.py startproject myproject


If you don't want other users on your shared host to have access to your DB settings, change the permissions on your myproject.settings file so that ONLY YOUR USER can read them.

chmod 600 myproject/settings.py


Edit the myproject.settings (myproject/settings.py) file to add your database connection parameters.

Initialize the database.

manage.py syncdb


Now its time to create the publicly available directory. Whether you set that up as a sub domain through CPanel or just create a sub-dir under ~/public_html (which you can always point to with a sub domain of the same name later) is your choice. For this exersize, we'll assume your just creating a sub-dir, which needs to have the fcgi.py script.

cd ~/www
mkdir myproject
cd myproject
wget http://svn.saddi.com/py-lib/trunk/fcgi.py
chmod 755 fcgi.py


Now you need to create a file named django.fcgi in the same dir, which should contain the following (replace 'username' with your username on lines 3 and 4 and 'myproject' with the name of your project if it differs from the example used above):

#!/usr/bin/python
import sys
sys.path += ['/home/username/django_src']
sys.path += ['/home/username/django_projects']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
WSGIServer(WSGIHandler()).run()


Set the correct permissions on django.fcgi.

chmod 755 django.fcgi


At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/. (Note: It usually takes a while for FastCGI to get ready and actually work. So, just let it sit on your server and keep on trying to access is it--because, for most people, it won't load on the first try.)

If you wish to pass everything in myproject dir through fast-cgi add the following to your .htaccess file within ~/www/myproject
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]


Deletions:
I almost have Django working on my tiny shared account. Actually, I think it works right, but I don't have the rewrite rules correct and that's causing the problem. Anyway, I'll step you through what I have so far.
First of all, you need to make sure you have Python2.3 for FCGI (and I think Django) to work. For more details about getting fcgi working, see this thread. You also need to have shell access. If you don't, submit a ticket to ASO support.
First, open your shell and confirm your version of Python (be sure to use a Capital V):
-jailshell-2.05b$ python -V
Python 2.3.4

If you have anything prior to 2.3.x you'll have to see about getting your server upgraded. (I'm told the new servers are at 2.3.x while the old are 2.2.x - if you just signed up for a new account, you should be good)
Ok, assuming your on one of the new servers, it's time to get started. Although Django is now offered both as a tarball and from svn, I chose to install from subversion as its easier to update to latest trunk etc. In your shell, make sure you're in your HOME dir and do:
cd ~
svn co http://code.djangoproject.com/svn/django/trunk/ django_src

Run the following commands: (so that Django is available from your shell)
export PATH=$PATH:$HOME/django_src/django/bin
export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects

Then add them to your .bash_profile file. Save the file, upload it and then continue with these instructions.
Create a Django projects directory and create your first Django project.
mkdir django_projects
cd django_projects
django-admin.py startproject myproject

If you don't want other users on your shared host to have access to your DB settings, change the permissions on your myproject.settings file so that ONLY YOUR USER can read them.
chmod 600 myproject/settings.py

Edit the myproject.settings (myproject/settings.py) file to add your database connection parameters.
Initialize the database.
django-admin.py init --settings=myproject.settings

Create a superuser account for use with the admin interface (follow the prompts).
django-admin.py createsuperuser --settings=myproject.settings

Now its time to create the publicly available directory. Whether you set that up as a sub domain through CPanel or just create a sub-dir under ~/public_html (which you can always point to with a sub domain of the same name later) is your choice. For this exersize, we'll assume your just creating a sub-dir, which needs to have the fcgi.py script.
cd ~/www
mkdir myproject
cd myproject
wget http://svn.saddi.com/py-lib/trunk/fcgi.py
chmod 755 fcgi.py

Now you need to create a file named django.fcgi in the same dir, which should contain the following (replace 'username' with your username on lines 3 and 4 and 'myproject' with the name of your project if it differs from the example used above):
#!/usr/bin/python
import sys
sys.path += ['/home/username/django_src']
sys.path += ['/home/username/django_projects']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
WSGIServer(WSGIHandler()).run()

Set the correct permissions on django.fcgi.
chmod 755 django.fcgi

At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/. (Note: It usually takes a while for FastCGI to get ready and actually work. So, just let it sit on your server and keep on trying to access is it--because, for most people, it won't load on the first try.)
If you wish to pass everything in myproject dir through fast-cgi add the following to your .htaccess file within ~/www/myproject
RewriteEngine On
RewriteBase /myproject/
RewriteRule ^(media/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(django.fcgi)
RewriteRule ^(.*)$ django.fcgi/$1 [L]

I'm getting some python errors regarding the url which is most likely because there are no rewrite rules yet. However, when I try anything that makes sense, I get a 403 Forbidden error - which indicates a problem with the rewrite rules, not Django. I'm still working on it.




Edited on 2006-04-15 20:24:41 by RaymondNunez

Additions:
At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/. (Note: It usually takes a while for FastCGI to get ready and actually work. So, just let it sit on your server and keep on trying to access is it--because, for most people, it won't load on the first try.)

Deletions:
At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/. (Note: It usually takes a while for FastCGI to get ready and actually work. SO, just le tit sit on your server and keep on trying to access is it-because, for most people, it won't load on the first try.)



Edited on 2006-04-15 20:24:13 by RaymondNunez

Additions:
At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/. (Note: It usually takes a while for FastCGI to get ready and actually work. SO, just le tit sit on your server and keep on trying to access is it-because, for most people, it won't load on the first try.)

Deletions:
At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/.



Edited on 2006-04-15 20:14:34 by RaymondNunez

Additions:
Then add them to your .bash_profile file. Save the file, upload it and then continue with these instructions.

Deletions:
Then add them to your .bash_profile file. Save the file, upload it and then continue.



Edited on 2006-04-15 20:14:11 by RaymondNunez

Additions:
Run the following commands: (so that Django is available from your shell)
Then add them to your .bash_profile file. Save the file, upload it and then continue.


Deletions:
Edit your .bash_profile file, and add the PYTHONPATH and PATH vars so that Django is available from your shell.



Edited on 2006-04-14 22:21:38 by RaymondNunez [Edited the python paths.]

Additions:
Edit your .bash_profile file, and add the PYTHONPATH and PATH vars so that Django is available from your shell.

Deletions:
Edit your PYTHONPATH and PATH vars so that Django is available from your shell.



Edited on 2006-04-06 16:54:48 by AdamStokes [Add proper re-write rules]

Additions:
At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/.
If you wish to pass everything in myproject dir through fast-cgi add the following to your .htaccess file within ~/www/myproject
%%RewriteEngine On
RewriteBase /myproject/
RewriteRule ^(media/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(django.fcgi)
RewriteRule ^(.*)$ django.fcgi/$1 [L]
I'm getting some python errors regarding the url which is most likely because there are no rewrite rules yet. However, when I try anything that makes sense, I get a 403 Forbidden error - which indicates a problem with the rewrite rules, not Django. I'm still working on it.


Deletions:
At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/. I'm getting some python errors regarding the url which is most likely because there are no rewrite rules yet. However, when I try anything that makes sense, I get a 403 Forbidden error - which indicates a problem with the rewrite rules, not Django. I'm still working on it.



Edited on 2006-04-03 15:04:30 by TimDorr

Additions:
I almost have Django working on my tiny shared account. Actually, I think it works right, but I don't have the rewrite rules correct and that's causing the problem. Anyway, I'll step you through what I have so far.

Deletions:
I almost have [url=http://www.djangoproject.com/]Django[/url] working on my tiny shared account. Actually, I think it works right, but I don't have the rewrite rules correct and that's causing the problem. Anyway, I'll step you through what I have so far.



Oldest known version of this page was edited on 2006-04-03 14:53:54 by TimDorr []
Page view:
I almost have [url=http://www.djangoproject.com/]Django[/url] working on my tiny shared account. Actually, I think it works right, but I don't have the rewrite rules correct and that's causing the problem. Anyway, I'll step you through what I have so far.

First of all, you need to make sure you have Python2.3 for FCGI (and I think Django) to work. For more details about getting fcgi working, see this thread. You also need to have shell access. If you don't, submit a ticket to ASO support.

First, open your shell and confirm your version of Python (be sure to use a Capital V):

-jailshell-2.05b$ python -V
Python 2.3.4


If you have anything prior to 2.3.x you'll have to see about getting your server upgraded. (I'm told the new servers are at 2.3.x while the old are 2.2.x - if you just signed up for a new account, you should be good)

Ok, assuming your on one of the new servers, it's time to get started. Although Django is now offered both as a tarball and from svn, I chose to install from subversion as its easier to update to latest trunk etc. In your shell, make sure you're in your HOME dir and do:

cd ~
svn co http://code.djangoproject.com/svn/django/trunk/ django_src


Edit your PYTHONPATH and PATH vars so that Django is available from your shell.

export PATH=$PATH:$HOME/django_src/django/bin
export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects


Create a Django projects directory and create your first Django project.

mkdir django_projects
cd django_projects
django-admin.py startproject myproject


If you don't want other users on your shared host to have access to your DB settings, change the permissions on your myproject.settings file so that ONLY YOUR USER can read them.

chmod 600 myproject/settings.py


Edit the myproject.settings (myproject/settings.py) file to add your database connection parameters.

Initialize the database.

django-admin.py init --settings=myproject.settings


Create a superuser account for use with the admin interface (follow the prompts).

django-admin.py createsuperuser --settings=myproject.settings


Now its time to create the publicly available directory. Whether you set that up as a sub domain through CPanel or just create a sub-dir under ~/public_html (which you can always point to with a sub domain of the same name later) is your choice. For this exersize, we'll assume your just creating a sub-dir, which needs to have the fcgi.py script.

cd ~/www
mkdir myproject
cd myproject
wget http://svn.saddi.com/py-lib/trunk/fcgi.py
chmod 755 fcgi.py


Now you need to create a file named django.fcgi in the same dir, which should contain the following (replace 'username' with your username on lines 3 and 4 and 'myproject' with the name of your project if it differs from the example used above):

#!/usr/bin/python
import sys
sys.path += ['/home/username/django_src']
sys.path += ['/home/username/django_projects']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
WSGIServer(WSGIHandler()).run()


Set the correct permissions on django.fcgi.

chmod 755 django.fcgi


At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/. I'm getting some python errors regarding the url which is most likely because there are no rewrite rules yet. However, when I try anything that makes sense, I get a 403 Forbidden error - which indicates a problem with the rewrite rules, not Django. I'm still working on it.
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.2
Page was generated in 0.3499 seconds