0

I want to make a registration form using flask_wft but this line never executed

if request.method == 'POST' and form.validate():

because form.validate() return False the reason is csrf_token. this is my code:

`@app.route('/', methods=['GET', 'POST'])
 def form():
     form = RegistrationForm(request.form)
     if request.method == 'POST' and form.validate():
     user = Person(f_name=form.firstName.data,
            l_name=form.lastName.data,
            email=form.email.data,city=form.city.data)
     db.session.add(user)
     db.session.commit()
     return redirect(url_for('welcome'))
 print('errors: '+ str(form.errors))
 return render_template('form.html', form=form)`

I got this error: 'csrf_token': ['The CSRF token is missing.']

How to solve the problem?

Hussein Saad
  • 151
  • 2
  • 15

1 Answers1

4

I just put this line {{ form.csrf_token() }} under 'form' tag

the Best Answer here

for more info: https://flask-wtf.readthedocs.io/en/v0.12/csrf.html

Hussein Saad
  • 151
  • 2
  • 15