Skip to content

Instantly share code, notes, and snippets.

@yoloseem
Forked from dahlia/gist:4407166
Last active December 11, 2015 11:38
Show Gist options
  • Save yoloseem/4595277 to your computer and use it in GitHub Desktop.
Save yoloseem/4595277 to your computer and use it in GitHub Desktop.
formencode htmlfill in jinja2 template
# htmlfill
with app.test_request_context('/'):
html = render_template_string('''
{%- autoescape true -%}
{%- form 'user.signin', {'method': 'POST'}
with {'name': 'sohee', 'pretty': 'no'},
{'pretty': 'sohee is always pretty.'} -%}
<input type="text" name="name" /> {{- '' -}}
<input type="text" name="pretty" placeholder="yes" /> {{- '' -}}
<div id="errors"> {{- '' -}}
<form:error name="name"> {{- '' -}}
<form:error name="pretty"> {{- '' -}}
</div>
{%- endform -%}
{%- endautoescape -%}
''')
expected = ('<form action="/u/signin" method="POST">'
'<input type="text" name="name" value="sohee" />'
'<input type="text" name="pretty" placeholder="yes"'
' class="error" value="no" />'
'<div id="errors">'
'<p class="error">sohee is always pretty.</p>'
'</div>'
'</form>')
assert html == expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment