43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
import sqlite3
|
|
from flask import Flask, render_template, request, url_for, flash, redirect
|
|
from werkzeug.exceptions import abort
|
|
|
|
def get_db_connection():
|
|
conn = sqlite3.connect('vokabeln.db')
|
|
conn.row_factory = sqlite3.Row
|
|
return conn
|
|
|
|
app = Flask(__name__)
|
|
app.config['SECRET_KEY'] = 'ClubhouseHurriedBoxerMosaicUnlawfulWanted'
|
|
|
|
@app.route('/', methods=('GET', 'POST'))
|
|
def index():
|
|
|
|
|
|
if request.method == 'POST':
|
|
vorname = request.form['vorname']
|
|
nachname = request.form['nachname']
|
|
telefonnummer = request.form['telefonnummer']
|
|
emailadresse = request.form['emailadresse']
|
|
anschrift = request.form['anschrift']
|
|
if telefonnummer == '' and emailadresse == '' and anschrift == '':
|
|
flash('Mindestens eine Eingabe zur Erreichbarkeit muss angegeben werden.','error')
|
|
else:
|
|
conn = get_db_connection()
|
|
conn.execute("INSERT INTO guests ( vorname , nachname, telefonnummer, emailadresse, anschrift) VALUES (?, ?, ?, ?, ?)",
|
|
(vorname , nachname, telefonnummer, emailadresse, anschrift)
|
|
)
|
|
conn.commit()
|
|
conn.close()
|
|
flash('Vielen Dank ' + vorname + ' ' + nachname + ' und viel Freude bei der Veranstaltung!','success')
|
|
return redirect(url_for('index'))
|
|
|
|
|
|
conn = get_db_connection()
|
|
vokabeln = conn.execute('SELECT * FROM vokabeln').fetchall()
|
|
conn.close()
|
|
return render_template('index.html', vokabeln=vokabeln)
|
|
|
|
if __name__ == '__main__':
|
|
app.run()
|