Concatenating strings in Django templates

Cheap ass hack to append a string within Django templates.

You might think that joining two strings in a Django template would have been simple and straightforward. In modern versions of Django, we can achieve it using the add filter.

{{ "Mary had a little"|add:" lamb." }}

However, in earlier versions of Django [TODO: identify specific version], the add filter only works with numbers. Using it on a string has no effect.

So how to do it?

It looks like we’re left with the stringformat filter. This feels quite dirty to me, but it works.

{{ "Mary had a little"|stringformat:"s lamb." }}

Enjoy!