Issue #12 new

extra_context callable item in views may return callable

Andrey Ikonnikov
created an issue

This code appears several times in views.py: {{{

!python

for key, value in extra_context.items(): context[key] = callable(value) and value() or value }}} If value() returns non-True, callable value gets in context. {{{

!python

extra_context = {1: lambda: 3, 2: lambda: 0} context = {} for key, value in extra_context.items(): ... context[key] = callable(value) and value() or value ... context {1: 3, 2: <function <lambda> at 0xb75bd5a4>} }}}

I believe this is solution: {{{

!python

extra_context = {1: lambda: 3, 2: lambda: 0} context = {} for key, value in extra_context.items(): ... context[key] = value() if callable(value) else value ... context {1: 3, 2: 0}

}}}

Comments (0)

  1. Log in to comment