简体   繁体   中英

WTForms doesn't validate MAC address

I'm using WTForms' MacAddress validator, but it doesn't recognize valid MAC addresses that I enter. 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. (12:34:56:78:AB:CD)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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