flaschengeist/geruecht.py

53 lines
1.3 KiB
Python

from flask import Flask, render_template, url_for, redirect, flash
from flask_sqlalchemy import SQLAlchemy
from forms import RegistrationForm
app = Flask(__name__)
app.config['SECRET_KEY'] = '0a657b97ef546da90b2db91862ad4e29'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
sum = db.Column(db.Float, nullable=False, default=0.0)
def __repr__(self):
return f"User('{self.username}', '{self.sum}')"
users = [
{
'name': 'Corey Schafer',
'sum': '20€'
},
{
'name': 'Tim Gröger',
'sum': '10€'
},
{
'name': 'Franziska Bobbe',
'sum': '5,80€'
}
]
@app.route("/", methods=['GET', 'POST'])
@app.route("/home", methods=['GET', 'POST'])
def home():
form = RegistrationForm()
if form.validate_on_submit():
flash(f'Person wurde angelegt: {form.username.data}', 'success')
return redirect(url_for('home'))
return render_template('home.html', users=users, form=form)
@app.route("/about")
def about():
return render_template('about.html', title='about')
if __name__ == '__main__':
app.run(debug=True)