spaceless_json
Now you can format and compress json-data in django template
- django
- templatetag
- json
- spaceless
- formatting
- application/id+json
Now you can format and compress json-data in django template
This is an enhancement of snippet [#172](http://djangosnippets.org/snippets/172/). Here I use [BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) — far more easier to install through pip in a virtualenv, and possibly a bit more maintained — to format and properly indent the rendered HTML from templates. I also added a check to only tidy contents in a `DEBUG=True` environment, regarding high impact on performance while doing so in production. Last, it's compatible with Django 1.2.x.
See the function **docstring** for usage. This template filter has a couple of drawbacks: * Uses **locale.setlocale** which, according to the [Python docs](http://docs.python.org/library/locale.html#locale.setlocale), is not thread safe. I don't know how this may affect Django applications. * Requires Python 2.5+. Updated 2011-03-16.
**Example usage**: {% copyright_since 2008 %}, {% copyright_since 2009 %} **Output**: © 2008—2009, © 2009 Use this templatetag in your footer to achieve proper formatting of copyright notice.
Just a simple regex function to convert a camel case string ("ClassName") to a lower case string with underscores ("class_name"). Came across a need for this when I was trying to add properties to a model at runtime using `object.__class__.__name__`. This is a modification of the function "get_verbose_name" found in django.db.models.options.
5 snippets posted so far.