我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用forms.RegistrationForm()。
def register(): form = RegistrationForm() if form.validate_on_submit(): employee = Employee(email=form.email.data, username=form.username.data, first_name=form.first_name.data, last_name=form.last_name.data, password=form.password.data) # add employee to the database db.session.add(employee) db.session.commit() flash('You have successfully registered! You may now login.') # redirect to the login page return redirect(url_for('auth.login')) # load registration template return render_template('auth/register.html', form=form, title='Register')
def GetUserFormById(user_id): user = orm.User.query.get(int(user_id)) if user is None: return None userform = RegistrationForm() userform.id.data = user.id userform.username.data = user.username userform.email.data = user.email userform.user_type.data = user.user_type return userform
def register(): form = RegistrationForm() if current_user.is_authenticated: return redirect(url_for('profile', username=current_user.username)) if form.validate_on_submit(): # Check to make sure username not taken if db_utils.user_exists(engine, form.username.data): flash('Username already taken.', 'danger') return redirect(url_for('register')) # Create user else: db_utils.create_user(engine, form.username.data, form.password.data, form.email.data) flash('Thanks for registering', 'success') return redirect(url_for('login')) return render_template('register.html', form=form)
def register(): """ Handle requests to the /register route Add an employee to the database through the registration form """ form = RegistrationForm() if form.validate_on_submit(): employee = Employee(email=form.email.data, username=form.username.data, first_name=form.first_name.data, last_name=form.last_name.data, password=form.password.data) # add employee to the database db.session.add(employee) db.session.commit() flash('You have successfully registered! You may now login.') # redirect to the login page return redirect(url_for('auth.login')) # load registration template return render_template('auth/register.html', form=form, title='Register')
def register(): """ Handle requests to the /register route Add an employee to the database through the registration form :return: redirect to auth.login route or stay in the page """ form = RegistrationForm() # if not a post, load the registration template if not form.validate_on_submit(): return render_template('auth/register.html', form=form, title='Register') # fill the form object employee = Employee(email = form.email.data, username = form.username.data, first_name = form.first_name.data, last_name = form.last_name.data, password = form.password.data) # add employee to the database db.session.add(employee) db.session.commit() flash('You have sucessfully registered! You may now login.') # redirect to the login page return redirect(url_for('auth.login'))
def register(): """ Handle requests to the /register route Add an employee to the db through the registration forms """ form = RegistrationForm() if form.validate_on_submit(): employee = Employee(email=form.email.data, username=form.username.data, first_name=form.first_name.data, last_name=form.last_name.data, password=form.password.data) # add employee to the database db.session.add(employee) db.session.commit() flash('You have successfully registered! You may now login.') # redirect to the login page return redirect(url_for('auth.login')) # load registration template return render_template('auth/register.html', form=form, title='Resigster')
def registration(): if g.user is not None and g.user.is_authenticated(): flash('Please Log out before registration') return redirect(url_for('index')) form = RegistrationForm() if request.method == 'POST' and form.validate_on_submit(): """ check is it avaliable login """ if User.query.filter_by(login=form.login.data).first(): """ Create error message """ flash('Choose another login', 'error') else: """ Add new user to DB """ new_user = User(login=form.login.data, password=bcrypt.generate_password_hash(form.password.data), name=form.name.data, surname=form.surname.data) db.session.add(new_user) db.session.commit() """ Success message """ flash('Done') return redirect(url_for("login")) return render_template('registration.html', title='Registration', form=form)