Document with docstrings.
Your functions and ORM models are currently not providing any useful documentation regarding their respective function within your program.
Don't initialize the database on module level:
You should put that into a function:
Base.metadata.create_all(engine)
Base.metadata.bind = engine
Session = (sessionmaker(bind=engine)) #scoped_session
Base.metadata.create_all(engine)
session = Session()
Don't do Pokémon Exception handling.
try:
if request.method == 'POST':
title = request.form['title']
release_date = request.form['release_date']
print(release_date)
session.add(Movie(title,date(int(release_date.split('-')[0]),int(release_date.split('-')[1]),int(release_date.split('-')[2]))))
session.commit()
session.close()
return redirect(url_for('table'))
except:
flash("An error occured while writing to database")
return redirect(url_for('home'))
return render_template('form.html', title = "Form")
This will catch any instance of BaseException and thus also KeyboardInterrupts and SytemExits. Also the error message is misleading, since it would also be printed on KeyErrors raised by request.form['title'] or request.form['release_date'], which implies a user input related error, rather than an error in writing to the database.
I suggest you familiarize yourself with the sqlalchemy exception APIs¹²1, 2 and handle anticipated exceptions selectively.