开发者

Can webpy form work well with jinja2?

As the cookbook of webpy and jinja2, I can use webpy's form or jinja2 well independently. However when I try to combining both in a template file like below, it does not work:

Template file:

$def with(form)
{% extends 'layout.html' %}
{% block maincontents %}
<h1>User</h1>
<form method="post">
  开发者_StackOverflow中文版  $:form.render()
</form>
{% endblock %}

Part of python code:

render = render_jinja(
    'templates',
    encoding='utf-8',
)

class test:
    def POST(self):
        pass

    def GET(self):
        f = user_form()
        return render.test(f)


$:form.render() is the Templetor rendering instruction, taken verbatim from the docs, I presume.

I believe you should use Jinja2 syntax, something like

<form method="post">
    {{ form.render() | safe }}
</form>

Disclaimer: I haven't actually tested the snippet above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜