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:

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
2016-10-09 18:40:29
Comments
Leave a Comment

Please login to continue.