0
我試着用變形金字塔。但是形式不呈現爲形式,而是一個純粹的字符串變形金字塔渲染不正常。呈現爲純字符串
@view_config(route_name='sign_up', renderer='templates/sign_up.jinja2')
def sign_up(request):
schema = SignUpForm().bind(request=request)
button = deform.form.Button(name='SignUp', title = 'Sign Up')
form = deform.form.Form(schema, buttons=(button,))
if request.method == 'POST':
try:
appstruct = form.validate(request.POST.items())
# Save the data to database
print('saved')
print(appstruct['username'])
request.session.flash('your have succesfully registered')
return HTTPFound('/')
except deform.exception.ValidationFailure as e:
rendered_form = form.render()
else:
print('rendering the form')
rendered_form = form.render();
return {'rendered_form': rendered_form}
這是使用Jinja2的模板我的HTML。在你的模板
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
{{rendered_form}}
</body>
</html>
所有形式的信息顯示了在瀏覽器
class SignUpForm(deform.schema.CSRFSchema):
username = colander.SchemaNode(
colander.String(),
title = 'Username')
password = colander.SchemaNode(
colander.String(),
title = 'Password')
完美解決方案!謝謝! – Bobby