Posts Tagged With ‘Django&8217


Book Review: Django 1.0 Template Development

I have finished reading free copy of Django 1.0 Template Development to review which is written by Scott Newman and published by Packt Publishing. I have already posted a blog entry about the free chapter of the book.

Django is a powerful Python web development framework which has challenging built in features like templating system, admin pages… etc. I have been developing web based applications for years and worked on variety of languages and platforms however Django’s clean and clear architecture is unique. The book focuses on the template development with Django and the content;

Detailed information about book content is available.

Django 1.0 Template Development is designed for both beginners and advanced developers and template authors with variety of examples and detailed topics of template development.

The book starts with introduction to template development and an overview of Django template system. Also, following Chapter 4 discusses built-in tags, filters and Chapter 7 focuses on custom tags and filters which are highly used important issues in Django application development.

I would recommend Django 1.0 Template Development for developers who want better understanding and efficient use of template systems in Django.


About Django Template Development

As you know I’m a python and django fan. I try to use python and django in every project including academic studies. A few days ago, I had the book “Django 1.0 Template Development” and still exploring it. Thanks to Packt Publishing.

As long as I finalize my current study, I’m going to start writing about django template development and a review about the book. There is a sample chapter “Serving Multiple Templates” which you can download and read for free.


A Real Django Application On A Shared Hosting

I got working a simple django application on a shared hosting before but never tried a real application till to night. I was developing a project for fun nothing much and it is about to finish and ready for a real time test. After struggling with .haccess mod_rewrite issues1 (mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use ‘RewriteOptions MaxRedirects’ to increase the limit if neccessary) my application is deployed and first http request is called. No, as you guess it didn’t work. My hosting provider uses an old version of mysql driver for python which is MySQLdb-1.2.0 but django 1.0 requires MySQLdb-1.2.1p2 or newer. So, planning to email and ask them if it is possible to upgrade driver if not I’m going to use my friends home servers to host it.

1 To fix this issue add your domain name to rewrite condition like
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} yoursite.com
RewriteCond %{REQUEST_URI} !yoursite.com
RewriteRule ^(.*)$ cgi/yoursite.cgi/$1 [QSA,L]


Django on Shared Hostings

I spent last night setting up django a cgi enabled shared hosting. I faced some problems during this process and I decided to write a how to about “django on shared hosting”.

First of all, make sure your editor supports Unix file format. It took my whole night to determine why I was getting internal server error. I tried some free editor on windows and it seems Komodo Edit is the best one.

Second, make sure your hosting supports python, to test it you can use this script below. Don’t forget to change file permissions (755 is fine) to run it.
#!/usr/bin/python
print "Content-type: text/html"
print
print "<pre>"
import os, sys
from cgi import escape
print "<strong>Python %s</strong>" % sys.version
keys = os.environ.keys()
keys.sort()
for k in keys:
print "%st%s" % (escape(k), escape(os.environ[k]))
print "</pre>"

Now, prepare two folders to store your python lib and django projects, in your hosting something like /home/username/python and /home/username/projects, then get django and flup unzip and upload these libraries to python folder and upload your site to projects folder. Don’t forget to change permissions of your project to 755.

Almost done, a script is need to handle request;
import sys, os
sys.path += ["/home/username/python"]
sys.path += ["/home/username/projects "]
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

You may need to place this script under the cgi-bin(or cgi) director. Some hosting providers don’t support fastcgi to run everywhere.

Now, modify and place following lines to your .htaccess file. mysite.cgi is the script above.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ cgi/mysite.cgi/$1 [QSA,L]

Done, call your domain, you will have django welcome message.


Django 1.0

Django 1.0 released. I wanna try soon…