0

I have two app routes in my flask app, the first collects customer data and then submits it to the database. The second collects address data then submits it to the database.

@app.route ('/register', methods=['GET', 'POST'])
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        customer_details = Customer(first_name=form.first_name.data, last_name=form.last_name.data, email_address=form.email_address.data)
        db.session.add(customer_details)
        db.session.commit()
        return redirect(url_for('register_address'))
    return render_template('register.html', title='Personal Details', form=form)

@app.route('/register_address', methods=['GET', 'POST'])
def register_address():
    form = AddressForm()
    if form.validate_on_submit():
        address_details = Address(house_no=form.house_no.data, first_line=form.first_line.data, second_line=form.second_line.data, postcode=form.postcode.data)
        db.session.add(address_details)
        db.session.commit()
        flash(f'Account created successfully')
        return redirect(url_for('home'))
    return render_template('register_address.html', title='Address Details', form=form)

In the register_address function I would like to submit all the database actions but I am not 100% sure how to do this. Any pointers on this would be good a idea.

Cheers.

fraserc182
  • 237
  • 1
  • 4
  • 13
  • this will [help youL /multiple-forms-in-a-single-page-using-flask-and-wtforms](https://stackoverflow.com/questions/18290142/multiple-forms-in-a-single-page-using-flask-and-wtforms) – sahasrara62 Jul 10 '20 at 13:52
  • This is somewhat related, but these forms are not on the same page. They are on different pages. – fraserc182 Jul 12 '20 at 17:39

0 Answers0