46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
import sys
|
|
from flask import Flask, redirect, url_for, request
|
|
from flask import render_template
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
from sqlalchemy import Integer, String
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
|
|
app = Flask(__name__)
|
|
# configure the SQLite database, relative to the app instance folder
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///database.db"
|
|
# initialize the app with the extension
|
|
db.init_app(app)
|
|
data = {}
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
class User(db.Model):
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
username: Mapped[str] = mapped_column(unique=True)
|
|
email: Mapped[str]
|
|
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
db = SQLAlchemy(model_class=Base)
|
|
|
|
@app.route("/", methods=["GET", "POST"])
|
|
def testpage():
|
|
global data
|
|
if request.method == "POST":
|
|
data = request.form
|
|
print(data)
|
|
return redirect(url_for("datapage"))
|
|
return render_template(
|
|
"layout1.html"
|
|
)
|
|
|
|
@app.route("/data")
|
|
def datapage():
|
|
return render_template(
|
|
"data.html",
|
|
value = str(data)
|
|
) |