heisel.org

My duh moment - Django and it’s lack of strip filter

Thursday | August 30, 2007 | 5:35 pm  

Had a total ‘duh’ moment today at work. I wanted to per­form the equiv­a­lent of Python’s string.strip method on some Django tem­plate output.

I looked on the Django doc­u­men­ta­tion site but I couldn’t find a strip filter.

It took me a few min­utes of con­ster­na­tion to figure why the devel­op­ers wouldn’t include such an oft-​needed filter.

And then, the afore­men­tioned duh moment, I real­ized that I could just call {% myvar.strip %} — because my output is a string and you can use Django’s dot syntax to call meth­ods, dic­tio­nary keys, etc.

Duh, I’m a moron.

So this post is writ­ten for Google in the hopes that some­one else sim­i­larly con­ster­nated will find this tidbit and be un-​consternated.

Permalink | Comments (0) | Categories: Django, Python

Comments

Be the first to post a comment!

Post a comment


Disclaimer: I work at The Atlanta Journal-Constitution. The opinions expressed here are my own, and do not reflect those of the AJC, Cox Newspapers, Cox Enterprises nor any other party.

Mail carrier N. Sorenson delivering Christmas mail through the snow. (Chicago Daily News/Chicago Historical Society)