【发布时间】:2021-10-03 09:22:35
【问题描述】:
编辑: 伙计们,三个小时后我解决了这个问题......
问题出在 html 依赖
**{{form.RegcheckEmial(name='email',placeholder='Email')}}**
name='email' 告诉我我的错误是这样解决的:
在 reg.html 中
我删除了
{{form.RegcheckEmial(name='email',placeholder='Email')}}
替换这个
{{form.RegcheckEmial(placeholder='Email')}}</br>
在 file.py 中
我删除了:
Email=request.form['email']
username=request.form['username']
password=request.form['password']
并替换了这个:
email=form.RegcheckEmial.data
user=form.Regcheckuser.data
password=form.Recheckpassword.data
dHi 伙计们,我的烧瓶有问题,控制台给我错误,例如 我不知道如何解决这个问题,我的 html 说我的表单未定义 我想检查输入数据的验证,如果数据已通过验证成功输入,请转到将数据发送到我的数据库 类
class LoginForm(FlaskForm):
checkEmial = StringField('checkEmial', validators=[InputRequired('A username is required!'), Length(min=5, max=50, message='Must be between 5 and 10 characters.'),Email(message='PLS ENETER CORRET Email')])
checkPassword = PasswordField('checkPassword', validators=[InputRequired('Password is required!'),Length(min=6, max=30, message='type the stronger password')])
class RegisterForm(FlaskForm):
RegcheckEmial=StringField('checkkEmiall',validators=[InputRequired('Please type value'),Length(min=5, max=50, message='Must be between 5 and 10 characters.'),Email(message='PLS ENETER CORRET Email')])
文件.py
@app.route('/reg.html',methods=['POST'])
def Register():
form=RegisterForm()
if form.validate_on_submit():
if request.method=='POST':
Email=request.form['email']
username=request.form['username']
password=request.form['password']
cur=mysql.connection.cursor()
cur.execute('''INSERT INTO dane (Email,username,UserPassword) VALUES (%s , %s , %s)''',(Email , username , password))
mysql.connection.commit()
cur.close()
return redirect(url_for('index'))
return render_template('reg.html',form=form)
reg.html
<div class="LoginSquare">
{% block content %}
<form method='POST' >
{{ form.csrf_token }}
{{form.RegcheckEmial(name='email',placeholder='Email')}} \
{% for error in form.RegcheckEmial.errors %}
<span style="color:red;">{{ error }}</br></span>
{% endfor %}
<div class="d1">
<input type='submit'name='Register' id='awdwd'class='wdawd'>
</div>
</form>
{%endblock%}
**index.html//(
this is my login page where I use LoginForm classes )**
<form method='POST' action="{{ url_for('index') }}" >
<div class="page1">
<img src="/static/pages/useerr.png" width="50px" height="50px">
</div>
<!-- {{form.csrf_token}} -->
{{ form.csrf_token }}
{{ form.checkEmial(placeholder='Email')}}</br>
{% for error in form.checkEmial.errors %}
<span style="color:red;">{{ error }}</br></span>
{% endfor %}
错误控制台:jinja2.exceptions.UndefinedError: 'form' is undefined, in top-level template code {% 块内容 %},文件“c:\python39\lib\site-packages\jinja2\environment.py”,第 474 行,在 getattr 返回 getattr(obj, 属性)
【问题讨论】: