def signup(): # specify where data is going to come from form = UserLoginForm() try: if request.method == 'POST' and form.validate_on_submit(): email = form.email.data password = form.password.data # Print just to confirm it worked print(email, password) # Password is a keyword, so we have specify which one user = User(email, password=password) # Equivalent of an insert statement # Here we are inserting a user # From the models file db.session.add(user) # To actually place the info inside of the database # From the models file db.session.commit() flash(f'You have successfully created a user account {email}', 'user-created') return redirect(url_for('site.home')) except: raise Exception('Invalid Form Data: Please Check Your Form Inputs') return render_template('signup.html', form=form)
def signup(): form= UserLoginForm() try: if request.method== 'POST' and form.validate_on_submit(): email= form.email.data password= form.password.data print(email,password) user = User(email, password =password) db.session.add(user) db.session.commit() flash(f'YOu have successfully created a user account{email}', 'user-created') return redirect(url_for('site.home')) except: raise Exception('Invalid Form Data: Please Check your Form inputs') return render_template('signup.html', form= form)
def signup(): form = UserLoginForm() try: if request.method == 'POST' and form.validate_on_submit(): email = form.email.data password = form.password.data print(email, password) #do this after establishing database user = User(email, password=password) #create interface between database and user model #like an insert statement/session db.session.add(user) db.session.commit() flash(f'You have successfully created a user account {email}', 'user-created') return redirect(url_for('site.home')) except: raise Exception('Invalid Form Data: Please Check Your Form Inputs') return render_template('signup.html', form=form)
def signup(): form = UserLoginForm() try: if request.method == 'POST' and form.validate_on_submit(): email = form.email.data password = form.password.data print(email, password) user = User(email, password=password) db.session.add(user) #insert statement!!! db.session.commit() flash(f'You have successfully created a user account{email}', 'user-created') #flash from the Flask package return redirect(url_for('site.home')) #from Flask package except: raise Exception('Invalid Form Data: Please Check Your Form Inputs') return render_template( 'signup.html', form=form ) #What other contexts are avaiable? (input argument for render_template function)