Fifty-five: WTForms form validation of rendering template

 

This feature may seem powerful, but in reality tasteless

 

Import Form1 WTForms from, StringField, BooleanField, SelectField 
from wtforms.validators Import the Length, the ValidationError


class SettingForm (Form1):
username = StringField ( 'User name:', validators = [Length ( 3, 10, message = ' username length 3 ~ 10 ')])
tags = SelectField (' label: ', choices = [(' 1 ',' python '), (' 2 ',' java '), (' 3 ',' c ')] ) # drop-down selection box
remember = BooleanField ( 'Remember me:') # box

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.username-input{
background: red;
}
</style>
</head>
<body>
<form action="" method="post">
<table>
<tbody>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>{{ form.username.label }}</td>
<td>{{ form.username(class='username-input') }}</td>
</tr>
<tr>
<td>{{ form.tags.label }}</td>
<td>{{ form.tags() }}</td>
</tr>
<tr>
<td>{{ form.remember.label }}</td>
<td>{{ form.remember() }}</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="点击提交"></td>
</tr>
</tbody>
</table>
</form>

</body>
</html>

 

Guess you like

Origin www.cnblogs.com/zhongyehai/p/11845214.html