mako
mako copied to clipboard
emit warning when a block or def is named "body"
Migrated issue, originally created by Bérenger Enselme (@benselme)
This is using CPython 3.6.1
from mako.template import Template
if __name__ == '__main__':
s = Template("""aaaa<%block name="bodi"></%block>bbbb""").render()
assert s == 'aaaabbbb' # success
s = Template("""aaaa<%block name="body"></%block>bbbb""").render()
assert s == 'aaaabbbb' # failure, s == '\n '
Michael Bayer (@zzzeek) wrote:
this is expected behavior. "body" is a pre-existing name with special behavior and is documented here. It is possible people use it as a "block" name intentionally.
Bérenger Enselme (@benselme) wrote:
Thanks, I get it now. I was aware of the body() function but it was not obvious at all that naming a block "body" would overwrite it.
Changes by Michael Bayer (@zzzeek):
- changed title from "Blank output when there is a block named "body"" to "emit warning when a block or def is named "body""