Check raw SQL queries that Django ORM generates

To find out what queries Django generates behind all that ORM magic, make sure that settings.DEBUG=True, and then run:

>>> from django.db import connection
>>> connection.queries
[{'sql': u'SELECT `auth_user`.`id`, `auth_user`.`username`, 
`auth_user`.`first_name`, `auth_user`.`last_name`, `auth_user`.`email`, 
`auth_user`.`password`, `auth_user`.`is_staff`, `auth_user`.`is_active`, 
`auth_user`.`is_superuser`, `auth_user`.`last_login`, 
`auth_user`.`date_joined` FROM `auth_user` 
WHERE `auth_user`.`id` = 2 ',  'time': '0.002'}, ]

The connection.queries attribute spits out a list of dictionaries of all queries in order of execution. The dictionary contains the actual SQL executed along with the time it took for the same.

To see the last query run, you can use pop:

>>> connection.queries.pop

and to explore further methods, attributes on the connection object, you can always do:

>>> dir(connection.queries)

Static site generation frameworks

My homepage at sidmitra.com, started out as a single page portfolio, but since then has grown into multiple pages. It’s coded in simple static HTML, CSS, JS and with no moving parts.  A full blown content management system seems overkill in my case and also ‘cos I'm running it on App Engine. So i was looking for frameworks that would let me exploit the benefits of a full blown templating engine, but spit out a static site. I came across quite a few, which are listed below. I’ll be exploring the Python ones a little bit more to see if they fit my need. Somehow i feel the itch to make my own, though.

 

Python

Hyde - http://github.com/lakshmivyas/hyde/tree/

Sleepy-django - http://code.google.com/p/sleepy-django/

Stango - http://www.digip.org/stango/

Blatter - http://bitbucket.org/jek/blatter/

 

Ruby

Jekyll - http://github.com/mojombo/jekyll

Templette - http://github.com/jdunphy/templette

StaticMatic - http://staticmatic.rubyforge.org/

Nanoc - http://nanoc.stoneship.org/

Webby - http://github.com/TwP/webby

 

If you know of any more, even for other languages let me know in the comments. I’ll update this list further.

Django complains “Unable to Open Database File”, with SQLite3

This is a fairly common gotcha, that i had forgotten about until i wasted half a day troubleshooting it again.

To solve, make sure the database file itself is writable, and not only that, also make sure that the parent directory is writable as well so the database engine can make temporary files. So just chmod 777 to check if it works :-) but remember to choose your permissions carefully later.

Ref: http://code.djangoproject.com/wiki/NewbieMistakes#DjangosaysUnabletoOpenDatabaseFilewhenusingSQLite3