def register(): from blog.extend.EmailHelper import register_mail form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): pwd = User.make_random_passwd(email=form.email.data) user = User(email=pwd['email'], role=ROLE_USER, nicename=form.email.data, passwd=pwd['pwdmd5'], is_locked=User_LOCKED, register_ip=request.remote_addr, salt=pwd['salt']) user.register_date = datetime.datetime.now(), db.session.add(user) db.session.commit() user.passwd = pwd['pwd'] register_mail(user) flash(u'恭喜,注册成功!') Blog_info.new_user() return redirect(url_for('login')) return render_template('register.html', title=u'欢迎注册', form=form)