Write notes to use Flask for the first time in business. This time it is part 2.
The first is here
Web App Beginner Flask Tutorial
Create at least 3 files
__init__.py
--The contents are empty. It seems that you have to create it because you need a file named init.py when calling it as a moduledatebase.py
--DB setting filesmodels.py
--For class management to define table column informationpip install sqlalchemy
https://www.sqlite.org/download.html
After downloading something like sqlite-tools-win32 ~~~ .zip
from the above site,
Copy the contents of the exe file to the folder (~~~ / script /) specified as the Python command execution location in PATH.
SELECT
from models.models import TestModelContent
items = TestModelContent.query.all()
return render_template("index.html", items = items)
INSERT
from models.database import db_session
# from datetime import datetime
name = request.form["name"]
content = TestModelContent(name)
db_session.add(content)
db_session.commit()
UPDATE
content = TestModelContent.query.filter_by(id = request.form["update"]).first()
content.name = request.form["name"]
db_session.commit()
DELETE
content = TestModelContent.query.filter_by(id = id).first()
db_session.delete(content)
db_session.commit()
Recommended Posts