Had a total ‘duh’ moment today at work. I wanted to perform the equivalent of [Python’s string.strip method](http://www.python.org/doc/2.3/lib/module-string.html#l2h-819) on some [Django template output](http://www.djangoproject.com/documentation/templates/).
I looked on the [Django documentation site](http://www.djangoproject.com/documentation/templates/) but I couldn’t find a strip filter.
It took me a few minutes of consternation to figure why the developers wouldn’t include such an oft-needed filter.
And then, the aforementioned duh moment, I realized that I could just call {% myvar.strip %} {{ myvar.strip }} — because my output is a string and you can use Django’s dot syntax to call methods, dictionary keys, etc.
Duh, I’m a moron.
So this post is written for Google in the hopes that someone else similarly consternated will find this tidbit and be un-consternated.
I did the same duh too!
However, its {{ myvar.strip }} rather than {% myvar.strip %}…
😀
@Ian — Duh! #facepalm. Thanks for catching that!
Thank you! It should be documented somewhere though..
I was looking for this. Thank you!
Thank you for unconsternating me. 🙂
But how can you specify what you want to strip?
E.g. text.strip(“@”)
I was looking for this as well. I am a moron too 🙂
I got caught too 🙁
I got caught too 🙁
Thanks man, I got caught, too!
+1 moron