简体   繁体   English

WTForms不验证MAC地址

[英]WTForms doesn't validate MAC address

I'm using WTForms' MacAddress validator, but it doesn't recognize valid MAC addresses that I enter. 我正在使用WTForms的MacAddress验证程序,但无法识别我输入的有效MAC地址。 Why isn't it working? 为什么不起作用?

{'choice': [u'Invalid Mac address.']}
class EditForm(Form):
    choice = TextField('choice', validators=[DataRequired(), MacAddress()])

@app.route('/', methods=['GET', 'POST'])
def devicechoice():
    form = EditForm()

    if form.validate_on_submit():
        print form.choice.data
        return redirect(url_for('editdevice'))
    else: 
        print form.errors

    return render_template('devicechoice.html', form=form)
<form action="" method="post">
    {{ form.hidden_tag() }}
    {{ form.choice() }}
    <input type="submit">
</form>

Question has been answered by @Ketouem, Simply putting a ":" after every 2 characters of the Mac address validates the form. @Ketouem回答了这个问题,只需在Mac地址的每2个字符后添加一个“:”即可验证表格。 (12:34:56:78:AB:CD) (12:34:56:78:AB:CD)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM