Newer
Older
from flask import Blueprint, render_template, request, redirect
from config import url_for2
from models import Person
home_blueprint = Blueprint('home', __name__, url_prefix='/')
@home_blueprint.route('')
def home():
return render_template('index.html')
@home_blueprint.route('/hello/<name>')
def hello(name: str):
return "Hello, " + name
# Example CRUD route
@home_blueprint.route('/persons', methods=['GET', 'POST'])
def persons():
if request.method == "GET":
try:
rows = ""
for e in Person.get_all():
except Exception as e:
return f"App database error: {e}"
req_form = request.form
firstname = req_form.get('firstname')
age = req_form.get('age')
surname = req_form.get("surname")
Person.add(firstname, surname, int(age))
return redirect(url_for2('.persons'))
except Exception as e:
return f"Could not add entity: {e}"