0
我很可能錯過了一些明顯的東西,但我無法讓這個工作正常。我想要的是「微調器」小部件停止在最大(最小)值,並且不允許用戶選擇更高(更低)的值。我究竟做錯了什麼?燒瓶IntegerField小工具驗證器不工作
的觀點:
<html>
<head>
<title>Widget Question</title>
</head>
<body>
<form method=post action=''>
{{ template_form.my_intfield.label }} {{ template_form.my_intfield }}
</form>
</body>
</html>
控制器:
from flask import Flask, render_template, request
from wtforms import Form, IntegerField, widgets, validators
app = Flask(__name__)
app.secret_key='some secret'
class InputForm(Form):
# This is the problem line - I can spin past max or min.
my_intfield = IntegerField(label='My integer field', widget=widgets.Input(input_type='number'), validators=[validators.InputRequired(), validators.NumberRange(min=0, max=100)], default=100)
@app.route('/', methods=['GET', 'POST'])
def index():
form=InputForm(request.form)
return render_template('view.html', template_form=form)
if __name__ == '__main__':
app.run(debug=True)
我沒有得到一個錯誤,它只是不正常工作;即旋轉器不在100處停止,它繼續前進。我希望在高端停止100,並且不允許底端的負數。
你會得到什麼錯誤? – Nurjan
沒有錯誤,只是沒有按預期工作。請參閱帖子底部的修改。 –