Tag Archives: Python

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;

  • Chapter 1: An Introduction to the Django Template System
  • Chapter 2: Views, URLs, and Generic Views
  • Chapter 3: Template Context
  • Chapter 4: Using the Built-In Tags and Filters
  • Chapter 5: Loading and Inheriting Templates
  • Chapter 6: Serving Multiple Templates
  • Chapter 7: Custom Tags and Filters
  • Chapter 8: Pagination
  • Chapter 9: Customizing the Admin Look and Feel
  • Chapter 10: Caching Your Pages
  • Chapter 11: Internationalization

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.

Why Python?

Why Python? I have been thinking and asking myself why I have chosen python while there are so many programming languages. Is it powerful, scientific, elegant, community, different??? You can find all of it in any programming language (or platform) so, what is it? Yesterday, I found something that can help to answer this question. The Python Paradox article written by Paul Graham. He says:

“… Python programmers are smart. It’s a lot of work to learn a new programming language. And people don’t learn Python because it will get them a job; they learn it because they genuinely like to program and aren’t satisfied with the languages they already know…”

Neither java nor c# describes me, the closest one is python.

Software Development & Deployment with Google App Engine

I have been developing applications for 5 years and worked on wide range of programming languages and platforms. If we exclude my undergraduate studies (like; tiny applications working on embedded devices or cross platform compiled iphone apps … etc.) briefly my experience on software development;

  • php on unix/linux
  • java/j2ee using hibernate on unix/linux
  • java/jee using glassfish on unix/linux
  • asp/asp.net on windows
  • python using django unix/linux
  • python using django on google app engine

So, far I have dealt with many programming languages, platforms and most of them have painful development/deployment processes except one.  Google App Engine is the only platform that I have never had problems with software deployment.  I doesn’t matter which box you have (mac, win, linux ..etc)  for development, deployed application works as it in your local. You don’t have to worry about changes about model, app engine handles it smoothly. It is amazing. I have never seen such a thing before. Even I had problems with php but not with app engine. That’s why Google like companies must exits, they are the real innovators.

A Twisted Weekend

I spent my weekend working on my graduate studies and watching South Park. Only a few episodes left to complete all missed episodes.

I made my mind with help of my advisers and decided to study on Peer-to-Peer (P2P) Semantic Networks and made a three phase plan. First phase is supposed to finish in three weeks time. That’s why I spent most of my weekend implementing a p2p network using twisted networking framework.

It is an implementation of simple client-client p2p network which is designed to work in local networks and doesn’t support file transfer protocol at the moment. So, it is the simplest p2p network that each peer can discover and talk each other for specific tasks. It is planned to accomplish basic p2p operations to test our main semantic application.

Now, next step is to add some semantics to this p2p network, so, I’ll be working on NLTK (NLP, Natural Language Toolkit) for two weeks.

PS: Twisted GUI integration easier then cli (command line interface). Strange, isn’t it?

Tell Me Again, What was The Semantic Web?

My semantic web interest is almost two years old however, I haven’t focused it enough till this year. It was something like a magazine or a blog that I like to read or follow but never involved. Somehow, my viewpoint on semantic web extremely changed and I’ve started scientific (also business) researches on semantic web.

Today, I felt much better when I saw the following videos. It was a right choice to make investments on semantic web. I hope, it will much better… Thanks Cas for sharing these nice videos:


Future Internet Video from Castemelijn on Vimeo

Impressed Kevin Kelly’s presentation and the quote about web: “Have to get better in believing the impossible”

Tomorrow, I have a meeting with my advisers about Semantic Web for P2P networks and if it goes successfully, I’ll start build my project in the following weeks. First, I want to up and running simplest p2p network in my local machine using twisted on python or jxta on java. Then give this thing a mining: semantic …

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]

I’m Free For a While

I woke up at 4:30 am last night and it is about to 2:00 am. Yes, It makes a lot of time. I was dealing with graduate studies for last two weeks and I’ve completed most important part this night. I made a paper submission to local conference in Turkey which will be held at Harran Uni. Only a few final exams left which are not a big issue to handle.So, I’m free for a while and my plan is to complete the following todo list:

  • specify my theses subject ( probably on semantic web)
  • focus on some important (and funny) projects.
  • blog more about python(python euro ) and semantic web
  • practice some Red Alert 3 against Japanese
  • add new things to this todo list

Trying to figure out Is it possible to say “free for a while” while having this list.

Why didn’t I quit and sleep instead of blogging?

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.

Building Python Modules on Windows

Python is a great cross platform application development environment. There is a  wide range of python modules (libraries) available. In most cases, module distributors supply platform specific installers which already built or at least they distribute the source code and let it to be built and installed by developers.

It is easy to build and install any python module in a Unix system. Because all *nix systems have a built in  development environment to build python modules ( or any language). So, just typing “python setup.py buil” and “python setup.py install” will be enough to get things done. Hard part is
having a windows. There are some options this issue:

1 -) Using MS Visual Studio ( I hate it)
2 -) Using Cygwin to get gcc for Windows
3 -) Using MinGW to get gcc for Windows

I choosed the 3rd option, it is the easiest one. What you have to do is get MinGW installer
and install required compilers and set it to your OS path. Mine is “C:MinGWbin”. Then, open a command prompt and cd to the source folder of the python module. Run build statement “python setup.py build -c mingw32″ this will build your module and get it ready to use. The build tool will generate a folder called “buildlib.win32-*.*” which contains compiled libraries. Copy those libraries to somewhere in python classpath. Mine is located at “C:Python25Lib”. That is it.You are ready to use your module. To test it, you can use pycrypto.