My blog is now being hosted by (mt) and written using Django. I have been waiting for the opportunity to create my blog using Django for quite some time. The second I saw that (mt) would be supporting Django I signed up for the beta tester program. So far everything has gone extremely smoothly.
Setting up my Django container was drop dead easy. (mt) provided excellent documentation for setting things up. The first thing I did was create a symbolic link in my home directory to the containers directory:
ln -s /home/##/containers ~/containers
Then I needed to change to the containers directory to create the django
directory where I can store projects. (mt) tends to use apps and projects
interchangeably which is slightly annoying:
cd containers
mkdir django
(mt) has Python 2.4.4 installed. Not a big deal for me, but it would be nice
to see 2.5.1 installed. I started with 2.4.4 and have pretty much used it until
just recently. I then changed into the django directory I just created
and ran django-admin.py and said that it did not exist. I went back to
the docs and found that I missed a step. I needed to setup my Python and Django
environment:
mtd setup_pylibs
mtd switch_to_svn
source .bash_profile
Ah, there we go. All set. I would like to point out the use of mtd. mtd
is a (mt) program that performs all container related tasks such as creating
the environment, starting, stopping and restarting the container, etc... mtd
is actually a command that is a shortcut to mtc django. It works very well,
but there is one thing that is getting annoying. Everytime you run the command
you need to give your username and password. It can be passed through the
command using -u and -p, but that just makes things less secure and
more verbose.
Now I am ready to go to town. I then created my Django project:
cd ~/containers/django
django-admin.py startproject oebfare
Bingo! A django project ready to be used. I modified a few files for a quick test of my container. However, you are not done yet. You must tell (mt) that you have a project to add. (The (mt) docs call this an app.):
mtd add oebfare /home/##/containers/django/oebfare oebfare.com
The first parameter is the name of the app, then the path, and finally the virtual host you want to serve request through. Pretty dang simple. Now I needed to create the bridge between Apache and the lighttpd process the container uses:
mtd generate_htaccess oebfare
Once again you will use the name of the app you assigned in the add stage
to perform commands against that Django project. It utimately lets you have
multiple projects under different names.
The generate_htaccess command will add some code to the virtual host
.htaccess file found in /home/##/domains/oebfare.com/html/.htaccess. This
is what it created:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://x.x.x.x:2011/${escape:$1} [P]
I masked out the internal IP just because it really isn't needed in showing everyone. And now you have configured the Django project to be used in the container. I am now ready to rock and roll. Let me get the container started and tested:
mtd start oebfare
And the lovely welcome to Django page popped right up. I then went ahead and developed my project to end up with what I have now. I am using djog, a Django blog app, that I am working on with Alex.
I ran into an issue with static media and the container. Well, at first I was
no idea what I should do. I quickly noticed that mtd created a new directory
at /home/##/containers/django/mt_runtime and contains some lighttpd
configuration files. Static files could be served using Django, but that is
highly recommended against and for good reason. I modified the
mt_lighttpd.conf file and MEDIA_URL in my settings.py file. Restarted
the container:
mtd restart oebfare
It all worked nicely. For those interested I simply added another alias url to
alias.url to point to my static content. Then added the correct
url.rewrite-once entry:
alias.url = (
"/media/" => "/home/##/data/python/django/django/contrib/admin/media/",
"/static/" => "/home/##/users/.home/containers/django/oebfare/static/",
)
url.rewrite-once = (
"^(/media.*)$" => "$1",
"^(/static.*)$" => "$1",
"^/favicon\.ico$" => "/media/favicon.ico",
"^(/.*)$" => "/main.fcgi$1",
)
That is pretty much it. Thus far everything worked smoothly. If you are a beta tester let me know how you got yours working. I would be interested in hearing other solutions or even improvements to my own solution.

zLQiSK <a href="http://tizfztssbmqf.com/">tizfztssbmqf</a>, [url=http://ektwurdswiyo.com/]ektwurdswiyo[/url], [link=http://wlzztccymfhy.com/]wlzztccymfhy[/link], http://cvitsfuohwch.com/
Posted by flimxo on May 7, 2008 at 9:57 AM