django_utils.templatetags package

Submodules

django_utils.templatetags.debug module

class django_utils.templatetags.debug.Formatter(max_depth=3)[source]

Bases: django_utils.templatetags.debug._Formatter

MAX_LENGTH = 100
MAX_LENGTH_DOTS = 3
format(value, depth, show_protected, show_special)[source]

Call the formatter with the given value to format and optional depth

>>> formatter = Formatter()
>>> class Eggs: pass
>>> formatter(Eggs)
'<Eggs {}>'
format_datetime(value, depth, show_protected, show_special)[source]

Format a date

Parameters:
  • value – a date to format
  • depth – the current depth
Returns:

a formatted string

>>> formatter = Formatter()
>>> formatter(datetime.date(2000, 1, 2))
'<date:2000-01-02>'
>>> formatter(datetime.datetime(2000, 1, 2, 3, 4, 5, 6))
'<datetime:2000-01-02 03:04:05.000006>'
format_dict(value, depth, show_protected, show_special)[source]

Format a string

Parameters:
  • value – a str value to format
  • depth – the current depth
Returns:

a formatted string

>>> formatter = Formatter()
>>> formatter({'a': 1, 'b': 2}, 5)
'{a: 1, b: 2}'
format_int(value, depth, show_protected, show_special)[source]

Format an integer/long

Parameters:
  • value – an int/long to format
  • depth – the current depth
Returns:

a formatted string

>>> formatter = Formatter()
>>> str(formatter(1, 0))
'1'
>>> formatter(1, 1)
'1'
format_list(value, depth, show_protected, show_special)[source]

Format a string

Parameters:
  • value – a list to format
  • depth – the current depth
Returns:

a formatted string

>>> formatter = Formatter()
>>> formatter(list(range(5)))
'[0, 1, 2, 3, 4]'
format_model(value, depth, show_protected, show_special)[source]

Format a string

Parameters:
  • value – a str value to format
  • depth – the current depth
Returns:

a formatted string

>>> formatter = Formatter()
>>> from django.contrib.auth.models import User
>>> user = User()
>>> del user.date_joined
>>> str(formatter(user, 5, show_protected=False)[:30])
'<User {email: , first_name: , '
format_object(value, depth, show_protected, show_special)[source]

Format an object

Parameters:
  • value – an object to format
  • depth – the current depth
Returns:

a formatted string

>>> formatter = Formatter()
>>> original_max_length = formatter.MAX_LENGTH
>>> formatter.MAX_LENGTH = 50
>>> class Spam(object):
...     x = 1
...     _y = 2
...     __z = 3
...     __hidden_ = 4
>>> spam = Spam()
>>> str(formatter(spam, show_protected=True, show_special=True))
'<Spam {x: 1, _Spam__hidden_: 4, _Spam__z: 3, __dict__:...}>'
>>> str(formatter(spam, show_protected=False, show_special=False))
'<Spam {x: 1}>'
>>> formatter.MAX_LENGTH = original_max_length
format_str(value, depth, show_protected, show_special)[source]

Format a string

Parameters:
  • value – a str value to format
  • depth – the current depth
Returns:

a formatted string

>>> formatter = Formatter()
>>> str(formatter('test'))
'test'
>>> str(formatter(six.b('test')))
'test'
format_unicode(value, depth, show_protected, show_special)[source]

Format a string

Parameters:
  • value – a unicode value to format
  • depth – the current depth
Returns:

a formatted string

>>> formatter = Formatter()
>>> original_max_length = formatter.MAX_LENGTH
>>> formatter.MAX_LENGTH = 10
>>> str(formatter('x' * 11))
'xxxxxxx...'
>>> formatter.MAX_LENGTH = original_max_length
django_utils.templatetags.debug.debug(value, max_depth=3)[source]

Debug template filter to print variables in a pretty way

>>> str(debug(123).strip())
'<pre style="border: 1px solid #fcc; background-color: #ccc;">123</pre>'

Module contents