Python Flask 应用中 NameForm 对象为何没有 'validate_on_submite' 属性?-灵析社区

米小米会努力

python小白,今天按课本上的实例写了如下代码,运行后一直报错:AttributeError: 'NameForm' object has no attribute 'validate_on_submite' ,上网查之后说是可能导入了两个Form,导致后面的Form覆盖前面导入的Form,我仔细地核对了一遍,并没有发现这个问题,已经校对了一下午,仍不能运行,通过自查也不能解决,现向各位大佬求助。另外,我的VScode不能识别validate_on_submite,也不知道什么原因,截图如下: from flask_wtf import FlaskForm from wtforms import StringField, SubmitField from wtforms.validators import DataRequired from flask import Flask, render_template, session, redirect,url_for # from collections.abc import Sequence # import _collections_abc # from typing import Any, Mapping app=Flask(__name__) app.config["SECRET_KEY"] = "123456" class NameForm(FlaskForm): name = StringField('What is your name?', validators=[DataRequired()]) submit = SubmitField('Submit') @app.route("/",methods=["GET", "POST"]) def index(): name=None form = NameForm() if form.validate_on_submite(): name = form.name.data form.name.data = '' return render_template('index1.html', form=form, name=name) # old_name=session.get("name") # if old_name is not None and old_name !=form.name.date: # flash("看看你输入的什么") # session["name"] = form_name_data # return redirect(url_for("index")) # return render_template("index1.html",form = form, name = session.get("name")) if __name__=="__main__": app.run(debug=True) ![](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240927/82b08e28ee6738b6ea7b3fc01dcc1058.png) 求助各位大佬

阅读量:150

点赞量:0

问AI
方法名称拼写错误,"form.validate_on_submit()", 另外如果vscode不识别的话可以加上类型注解"form: NameForm = NameForm()"