django_utils.templatetags package¶
Submodules¶
django_utils.templatetags.debug module¶
Bases:
django_utils.templatetags.debug._Formatter
Call the formatter with the given value to format and optional depth
>>> formatter = Formatter() >>> class Eggs: pass >>> formatter(Eggs) '<Eggs {}>'
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 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 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 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 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 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 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 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
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>'