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 %}
`
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 %}
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)
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 %}
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.
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!
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.
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`
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/)
Humanized and localized version of built-in *timesince* template filter.
Based on [Joey Bratton's idea](http://www.joeyb.org/blog/2009/10/08/custom-django-template-filter-for-humanized-timesince).