utils.functional.keep_lazy_text()

keep_lazy_text(func) [source]

New in Django 1.10.

A shortcut for keep_lazy(six.text_type)(func).

If you have a function that returns text and you want to be able to take lazy arguments while delaying their evaluation, simply use this decorator:

1
2
3
4
5
6
7
8
9
10
11
12
from django.utils import six
from django.utils.functional import keep_lazy, keep_lazy_text
 
# Our previous example was:
@keep_lazy(six.text_type)
def fancy_utility_function(s, ...):
    ...
 
# Which can be rewritten as:
@keep_lazy_text
def fancy_utility_function(s, ...):
    ...
doc_Django
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.