Open vasudev430 opened 5 years ago
solution: after watching the video u might have done like this
@app.route('/register',methods =['GET','POST']) def register(): form = RegisterForm(request.form) if request.method =='POST' and form.validate(): name = form.name.data email = form.email.data username = form.username.data password = sha256_crypt.encrypt(str(form.password.data))
# create cursor
cur = mysql.connection.cursor()
cur.execute("INSERT INTO users(name,email,username,password) VALUES(%s,%s,%s,%s)",(name,email,username,password))
# commit to Database
mysql.connection.commit()
# close connection
cur.close()
flash('you are now registered and can login ','success')
redirect(url_for('index'))
return render_template('register.html')
return render_template('register.html',form = form)
##########################################################################################
now instead of doing like that just do like this ##########################################################################################
@app.route('/register',methods =['GET','POST']) def register(): form = RegisterForm(request.form) if request.method =='POST' and form.validate(): name = form.name.data email = form.email.data username = form.username.data password = sha256_crypt.encrypt(str(form.password.data))
# create cursor
cur = mysql.connection.cursor()
cur.execute("INSERT INTO users(name,email,username,password) VALUES(%s,%s,%s,%s)",(name,email,username,password))
# commit to Database
mysql.connection.commit()
# close connection
cur.close()
flash('you are now registered and can login ','success')
redirect(url_for('index'))
return render_template('register.html',form = form)
return render_template('register.html',form = form)
Getting below error: jinja2.exceptions.UndefinedError: 'form' is undefined
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.
You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection: