• 22. Feb
  • 23:11
  • 2010

  • Updated
  • 19. Sep
  • 16:40
  • 2010

Django Extensions

This small post is basically a note to myself. It's about the famous django-extensions (formerly django-command-extensions), to be more specific it's about the runscript command.

Update: As Andrzej wrote in the comments, appending -v 2 as argument tells you that your script needs a run() method.

So, django-extensions adds a lot of nice commands to your django's manage.py. One of these commands is runscript, which runs a python script inside your project's context. This means that you do not have to fiddle with the sys.path inside your script. Anyway, one thing always kept me away from using it:

> No module for script 'devlol' found

The message is kind of obvious to be honest. It couldn't find the module, in this example, devlol.py. However, it really irritated me all the time, because devlol.py exists, is in the, not so right, path. I even tried giving it it's own folder. Nothing worked. Yesterday I stumbled upon the following thing in dumpscript's documentation:

> Note: Runscript needs scripts to be a module, so create the directory and a __init__.py file.

Finally, this makes runscript work. Inside your project root (where manage.py lives):

mkdir scripts
touch scripts/__init__.py

and put your scripts there.

mv devlol.py scripts/devlol.py

et voila

python manage.py runscript devlol

should work.

I definitly love django-extensions. Nevertheless I think runscripts deserves it's own small wiki page, telling on how to use it properly. Well, maybe I was just too dumb.

blog comments powered by Disqus

This is Luis’ blog. Here he posts about stuff that he encounters in everday life, both virtual and real.

Recently he wrote “Complete Facebook Profile?”, “Lighttpd's X-Sendfile”, “Modular Lighttpd Configurations”, “Fool Facebook's Like-Button” and “Calculating Battery Health”.

Contact