Login

Tag "template"

Snippet List

grouper tag

I needed to display formset into table and I didn´t like solution I have found. So I have written this simple tag you can use it in templates like this: ` {% for row in formset|square_it:6 %} <tr> <td> </td> {% for form in row %} <td> {% for field in form %} {{ field }} {% endfor %} </td> {% endfor %} `

  • template
  • tag
  • templatetag
  • formset
Read More

tag to store a settings value as template variable

Get any value from settings.py as a template variable. The variable can then be used in conditional tags. E.g. to show a link to a help page only if it the help page url is defined in settings.py {% load get_setting %} {% get_setting MY_HELP_URL as help_url %} {% if help_url %}<a href="{% help_url|safe %}">Help</a>{% endif %}

  • template
  • tag
  • templatetag
  • settings
Read More

Loading templates by app path

Loading templates by path app.template_name -> app/templates/template_name.html app.subdir.template_name -> app/templates/subdir/template_name.html Usage: append in settings.TEMPLATE_LOADERS and using render_to('app.index', context)

  • template
  • loader
Read More

HTML5 filter for XXS

Usefull for TinyMCE, to allow some HTML but be vunarable by XXS attacks You need to install html5lib sudo easy_install html5lib

  • template
  • filter
  • security
  • sanitize
  • xss
Read More

template filter to check login status

In templates sometimes you need to display some menu by checking whether the user is logged in or not. So use the above filter as shown below {% with request|check_login as logout %} {% if logout%} display something.... {% endif %} {% endwith %}

  • template
  • filters
  • custom
Read More

Pygmentify a code using template filter

The above snippet can be added as a custom filter for rendering code snippets in django templates. A simple '|render' next to any source code will do. To add css, use the following command to generate css file. pygmentize -S emacs -f html > pygments-colorful.css And link this css file to the template.

  • template
  • django
  • pygments
  • custom-filters
Read More

Smart Spaceless

This 'smart_spaceless' template tag is a replacement for Django's built-in 'spaceless'. If settings.DEBUG = True, spaces will not be removed to make debugging your template code easier. When DEBUG = False, spaces will be removed. Happy coding!

  • template
  • spaceless
  • template tag
  • remove spaces
  • template tags
Read More

Truncate text to length up until the nearest space

This will truncate a long character based on the given length parameter. If the word is cut-off, it will return the string up until the next space. If there are no spaces in the next 5 characters, that should mean a very long word and we should truncate right away.

  • template
  • string
  • truncate
Read More

currency filter without using locale

This snippet is a combination of the existing currency snippets I found and some modifications to use your own settings without the need to have the locale installed on the system. You can define in settings.py: DECIMAL_SEPARATOR = ',' THOUSAND_SEPARATOR = '.' CURRENCY_SYMBOL = u'€' With the above settings, using `{{ 1234.30|currency }}` on a template would result in `€1.234,30`

  • template
  • filter
  • currency
Read More

Django 1.2 template tag {% IF %} with {% ELIF %} support

Adds to Django 1.2 tag `{% elif %}` {% if user.nick == "guest" %} Hello guest! {% elif user.nick == "admin" or user.is_admin %} Hello admin! {% elif user %} You are registered user {% else %} Login to site {% endif %} Snipped designed for [gaeframework.com](http://www.gaeframework.com) Inspired by snippets: [#1572](http://djangosnippets.org/snippets/1572/) and [#2243](http://djangosnippets.org/snippets/2243/)

  • template
  • if
  • elif
  • django 1.2
  • tags. tag
Read More

cleat_list

Clear list from unwanted elements, within django template.

  • template
  • filter
  • list
  • clear
Read More

is_in

I know in Django 1.2 we may acquire the same result using {% if value in arg %} but I need this filter in Django 1.1.

  • template
  • filter
  • django
  • contains
  • in
  • is
Read More

262 snippets posted so far.