import sqlite3 from flask import Flask, redirect, url_for, render_template, flash from forms import EntryForm app=Flask(__name__) app.config['SECRET_KEY'] = 'your_secret_key' @app.route("/") def home(): return render_template("home.html", message="abc") def init_db(): conn=get_db_connection() conn.execute("CREATE TABLE IF NOT EXISTS entries (id INTEGER PRIMARY KEY, title TEXT, content TEXT)") conn.close() def get_db_connection(): conn=sqlite3.connect("database.db") conn.row_factory=sqlite3.Row return conn @app.route('/add', methods=['GET', 'POST']) def add_entry(): form = EntryForm() if form.validate_on_submit(): conn = get_db_connection() conn.execute('INSERT INTO entries (name, title, content, age) VALUES (?, ?, ?, ?)', (form.name.data, form.title.data, form.content.data, form.age.data)) conn.commit() conn.close() return redirect(url_for('data')) return render_template('add.html', form=form) @app.route('/data') def data(): conn = get_db_connection() entries = conn.execute('SELECT * FROM entries').fetchall() conn.close() return render_template('data.html', entries=entries) if __name__=="__main__": init_db() app.run(debug=True)