Tag Archives: static

Django Compress Static Files and Compile CSS

I started off looking for a request time compiler of LESS for Django and initially found django-css which seems to serve the purpose great. Compressing static files on the fly is definitely a nice added bonus as well. It does so by containing a fork of django_compressor. But on further inspections, I jumped ship. The original project, django_compressor, sees a more regular update and is now Django 1.3 ready while the ‘successor’ isn’t. Funny thing is django_compressor supports compiling any CSS formats compilable via command line. With a better documentation overall, seems like the original has beat the sequel.


Python’s Function Static Variable

So you want a variable that stays between different calls of a function. Not the sexiest thing ever but always handy in small programs.

There’s tons of ways of doing this. You can embark on a quest to find the meaning of Pythonic or take this method that’s relatively simple:

def a():
    if not hasattr(a, "b"): a.b = 0
    a.b += 1
    print a.b

Calling a(), you’ll get 1, 2, 3, …

Note attribute ‘b’ of ‘a’ does not exist until you declare it for a first time. My main preference here is that ‘static’ variables used this way does not spill onto the rest of your code. Also, it’s clean, no classes, no data structures.