A little Django feature nobody tells you about

Recently i got involved in a new project which uses Django, so I started learning and using it. I won’t tell you here it merits as those have alread been described at lenght.

One of the features I like about Django are its pluggable applications: you can build a generic piece of code and that can easily be plugged in other’s sites to get some new functionality. Great examples of this are found in the django.contrib package, which include the already famous administrative interface, two comments systems, an authentication/authorization framework and more.

One problem you’ll soon find is that some of these are tied to be plugged at a fixed URL prefix. The auth system, for example, expects to be plugged in the /accounts/ directory and plugging it somewhere else leads to some more work for you. The easiest example is the @login_required decorator, which checks the user that is calling a view and, if it is not authenticated, it redirects to /accounts/login. If you have used a different URL prefix, you are forced to use the @user_passes_test decorator, which allows you to set the redirect URL.

Where is the problem? The problem is that those paths are explicitly hardocded in the views.

How to solve it? Dynamically build your URLs from your urlconf.

How do you do that? With django.core.urlresolvers.reverse()

A tale of Pylons, Python and FastCGI on Dreamhost

Pylons is a WSGI based Python Web Framework that tries to combine the best ideas from other existing frameworks and does so by glueing togheter existing projects and allowing to swap its components at will and easily extend its capabilites with other WSGI components.

I will explain here how I installed it and a demo application on Dreamhost and how to avoid the single problem I had.

This procedure isn’t specific to either Dreamhost or Pylons, it can be used anywhere and for any WSGI compliant application if you don’t have root access to install new modules or if you want to keep the system wide installation clean and add modules just for a single user.

Ruby and Python: perspectives

I just realized something interesting.

In Ruby you mix in modules that add methods to objects that implement interfaces.

In Python you have functions that you use on objects that implement interfaces.

How I read and backup my mail

I was going to answer Stuart’s question to the Lazyweb in a quick comment, but I figured my email set up, while essentially not really special, is a bit peculiar and might be interesting to somebody out there.

I have all my personal email on Gmail, but I also download it locally to keep a backup, just in case. The problem is that if you read your mail with Thunderbird, it ends up inside a directory with a funny name which in turn contains a funny mix of files of which you don’t know the purpose, so the backup (and the restore) is a bit unpractical.

The solution turned out to be quite easy: you retrieve your email and with some magic symlinks you make Thunderbird read that. The only limitations to this are that Thunderbird only supports mbox mailboxes and that it has to update its indexes every time it starts.

My final set up is that I can retrieve, read and send email with both mutt and Thunderbird and the mail is in plain mbox files that I can easily rsync around. Here’s how I did it.

Vim Tango color scheme

Things you do at the airport while waiting for the cute girl to call the boarding…

Finding that a Tango color scheme for my terminal was a nice idea, I made one for my Vim too.

screenshot

To use the Vim Tango color scheme you have to place the tango.vim file in the ~/.vim/colors/ directory and colorscheme tango in your ~/.vimrc.

Older posts: 1 2 3 4 ... 32