Mar 08

staticfiles: Keeping Media Files Up-to-date

A simple trick to keep using staticfiles while still having up-to-date media files.

While working on the next iteration of www.zukx.de I discovered a simple trick to keep my sanity while working with the staticfiles app.


As jezdez pointed out in the comments, that's actually a long solved problem. One can simply use the built in views to serve static files which uses the same traversal logic as the management command.

Thank you, jezdez.

I guess I'll keep using the trick, as a status console with information about the used media is still quite nice.


Simply put this neat little app adds a management command build_static which gathers all media/ files from all those reusable apps you should be using and puts them under a (configurable) target directory.

However when developing this lead to quite a few lost nerves as changes to specific css or javascript files had to be activated by issueing said command.

The trick in the end is quite simple, open a konsole and type in:

trillian$ watch python manage.py build_static --noinput

The watch command will execute the given command every 2 seconds, leading to near instant updating of your media files - while still keeping your directories symlink free.