采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
老师,在修改密码部分,旧密码提交后,并不能验证,是怎么回事?
同学,你好,注意一下旧密码命名是old_pwd不是pwd,表单的代码如下:
class PwdForm(FlaskForm): old_pwd = PasswordField( label="旧密码", validators=[ DataRequired("请输入旧密码!") ], description="旧密码", render_kw={ "class": "form-control", "placeholder": "请输入旧密码!", } ) new_pwd = PasswordField( label="新密码", validators=[ DataRequired("请输入新密码!") ], description="新密码", render_kw={ "class": "form-control", "placeholder": "请输入新密码!", } ) submit = SubmitField( '编辑', render_kw={ "class": "btn btn-primary", } ) def validate_old_pwd(self, field): from flask import session pwd = field.data name = session["admin"] admin = Admin.query.filter_by( name=name ).first() if not admin.check_pwd(pwd): raise ValidationError("旧密码错误!")
html代码如下:
<form role="form" method="post"> <div class="box-body"> <div class="form-group"> <label for="input_pwd">{{ form.old_pwd.label }}</label> {{ form.old_pwd }} {% for err in form.old_pwd.errors %} <div class="col-md-12"> <font style="color:red">{{ err }}</font> </div> {% endfor %} </div> <div class="form-group"> <label for="input_newpwd">{{ form.new_pwd.label }}</label> {{ form.new_pwd }} {% for err in form.new_pwd.errors %} <div class="col-md-12"> <font style="color:red">{{ err }}</font> </div> {% endfor %} </div> </div> <div class="box-footer"> {{ form.csrf_token }} {{ form.submit }} </div> </form>
非常感谢!
加油,有问题与我反馈!
@admin.route('/pwd/', methods=["GET", "POST"]) @admin_login_req def pwd(): form = PwdForm() if form.validate_on_submit(): form = form.data return render_template("admin/pwd.html", form=form)
{% extends "admin/home.html" %} {% block content %} <!--内容--> <section class="content-header"> <h1>微电影管理系统</h1> <ol class="breadcrumb"> <li><a href="#"><i class="fa fa-dashboard"></i> 个人资料</a></li> <li class="active">修改密码</li> </ol> </section> <section class="content" id="showcontent"> <div class="row"> <div class="col-md-12"> <div class="box box-primary"> <div class="box-header with-border"> <h3 class="box-title">修改密码</h3> </div> <form role="form" method="post"> <div class="box-body"> <div class="form-group"> <label for="input_pwd">{{ form.pwd.label }}</label> {{ form.pwd }} {% for err in form.pwd.errors %} <div class="col-md-12" style="color: red">{{ err }}</div> {% endfor %} </div> <div class="form-group"> <label for="input_newpwd">{{ form.new_pwd.label }}</label> {{ form.new_pwd }} {% for err in form.new_pwd.errors %} <div class="col-md-12" style="color: red">{{ err }}</div> {% endfor %} </div> </div> <div class="box-footer"> {{ form.csrf_token }} {{ form.submit }} </div> </form> </div> </div> </div> </section> <!--内容--> {% endblock %}
同学,你好,你检测old_pwd是否提交到服务器端,你截取一下修改密码的视图代码以及html代码给我!
老师,两端代码我已经提交到回答里面了。这里粘贴不了。
登录后可查看更多问答,登录/注册
Python 最好用轻量级框架,让你轻松胜任 Python Web 工程师
6.1k 8
2.3k 7
1.1k 6
996 6