Login

Snippets by bartTC

Snippet List

Create a random integer in a template

Create a random integer with given length. - For a length of 3 it will be between 100 and 999. - For a length of 4 it will be between 1000 and 9999. Use it in a template like: {% random_number as my_id %} The id is {{ my_id }}

  • template
  • django
  • templatetag
  • integer
Read More

Language aware cache decorator

Caches a view based on the users language code, a cache_key and optional function arguments. The cache_key can be a string, a callable or None. If it's None, the the name of the decorated function is used. You can pass a tuple `func_args` of arguments. If passed, these arguments are part of the cache key. See examples for details.

  • cache
  • decorator
  • caching
Read More

Language-aware template inclusion

Looks up for a template based on the template-name plus the current users language code. Loads the template and renders it with the current context. Example:: {% langinclude "foo/some_include.html" %} Based on the users LANGUAGE_CODE, assumed we have 'de', it tries to render the template 'foo/some_include.html.de'. If that doesn't exists, it renders the template 'foo/some_include.html'. This is the default behavior of the include-Tag. Basically this is a shortcut for the following code, just with a fallback for the default template:: {% ifequal LANGUAGE_CODE "de" %} {% include "foo/some_include.html.de" %} {% else %} {% include "foo/some_include.html" %} {% endifequal %} --- Ein deutscher [Weblogeintrag mit Beschreibung](http://www.mahner.org/weblog/sprachabhangige-template-imports/)

  • templatetag
  • i18n
  • language
  • include
Read More

Add rel=lightbox to all image-links

Add the attribute "rel='lightbox'" to all Links, if the target is an image. `<a href="/path/to/image.jpg">Image</a>` becomes `<a rel="lightbox" href="/path/to/image.jpg">Image</a>` Works for JPG, GIF and PNG Files.

  • filter
  • re
  • lightbox
  • regular-expression
Read More

bartTC has posted 6 snippets.