Search This Blog

Sunday, September 20, 2009

Django, Free Django Hosting

It is not English, but you know how to enter the information to create an account anyway :)
(10M free. more than enough to write lots of code, and you have ssh access too!)

Now, to get your free Django to work, it is very easy by just following their (non-English) wiki.

You will need two files, django.fcgi, and .htaccess on this shared hosting environment.
(You can copy and paste the two files below)
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")
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]

1. Create your Django project. startproject mysite
2. Create a "public" directory under "mysite"
3. put django.fcgi and .htaccess under the public directory

Your "mysite" structure will look like this:

Notice the media directory under public, you can create a soft link for that with
ln -s /var/lib/python/django/1.1/django/contrib/admin/media/ media

so, you can get the Django admin to work properly, i
it's django version 1.1 in this case.

Then, your "public" url is under Django's control!

e.g. If you follow the hello world example in the Django book, you can go
and it will print the happy Django's "hello world".

Last step:
Make sure you go to your administration panel. Go to domain, edit, and change your root directory to, for example, /www/mysite/public/
or people can view your source code :)

So you can use your free Django powered site with

tar your entire site and upload with ftp, and then untar.
remember to update the "TEMPLATE_DIRS" (using ABSOLUTE path), and update the "DATABASE_NAME" (using ABSOLUTE path if using sqlite)

also read:

No comments: