Вот мои коды:
Python
Код: Выделить всё
from datetime import datetime
from flask import Flask, render_template, request, flash, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config["SECRET_KEY"] = "xDxDxD"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///data.db"
db = SQLAlchemy(app)
class Form(db.Model):
id = db.Column(db.Integer, primary_key=True)
first_name = db.Column(db.String(80))
last_name = db.Column(db.String(80))
email_add = db.Column(db.String(150))
date = db.Column(db.Date)
occupation = db.Column(db.String(80))
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
first_name = request.form["first_name"]
last_name = request.form["last_name"]
email_add = request.form["email"]
date = request.form["date"]
date_obj = datetime.strptime(date, "%Y-%m-%d")
occupation = request.form["occupation"]
form = Form(first_name=first_name, last_name=last_name, email_add=email_add, date=date_obj, occupation=occupation)
db.session.add(form)
db.session.commit()
flash(f"{first_name}, your form was submitted successfully", "success")
return render_template("index.html")
if __name__ == "__main__":
with app.app_context():
db.create_all()
app.run(debug=True, port=5001)
Код: Выделить всё
Job Form
Job Application Form
First Name:
Last Name:
Email:
Available Start Date:
Current Occupation:
Employed
Unemployed
Self-Employed
Student
Submit
{% if messages %}
{% with messages = get_flashed_messages() %}
{% for message in messages %}
{{ message }}
{% endfor %}
{% endwith %}
{% endif %}
Подробнее здесь: https://stackoverflow.com/questions/792 ... after-relo