Login

Most bookmarked snippets

Snippet List

gettext parachut for python 2.3 with unicode and utf-8

I ran into this because my development system is django on python 2.4 and I deploy to 2.3. It's a corner case where you use gettext, the \# -\*- coding: utf-8 -\*- header and want to have a consistant style in your file. It is encouraged to use the unicode marker like u'string', but this does not work for __str__ methods of your models as they are called by the ``str'' function and that function again can not handle unicode. It would be really nice to have all unicode intern and only do the appropriated encoding on the output. Anyway. With this little helper you can clutter your files with _('stirng of heart with € äüöß') ... With the coding directive in the header python 2.4 and gettext can handle this on 2.3 though they can't. So this script adds a parachut to the gettext wrapper that kicks in if gettext is failing.

  • unicode
  • gettext
  • utf-8
  • 2.4
  • 2.3
Read More

Dynamically specify TEMPLATE_DIRS

In your site’s settings.py module (in your site root), TEMPLATE_DIRS takes absolute paths. Here is a way to dynamically determine the absolute path to the application directory so you only have to specify relative paths within settings.py. Obviously, replace “application_directory” with the name of your application’s directory.

  • configuration
Read More

Serving null files

Sometimes you have to serve null files. This quick hacky generic view lets you do that. The best example of that is robots.txt, I want my robots.txt to always be empty, at least for now. The other example would be favicon.ico, but that's more often used to actually fill a purpose.

  • null
  • files
  • views
Read More

3110 snippets posted so far.