Flask's personal note # 2

Write notes to use Flask for the first time in business. This time it is part 2.

The first is here

reference

Web App Beginner Flask Tutorial

DB (SQLite) operation

Creating a setting file

Create at least 3 files

Install sqlalchemy

pip install sqlalchemy

Make SQLite3 available from the shell

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

Flask's personal note # 2
Flask's personal note # 1
Note
Note
[AtCoder] ABC165C Personal Note [Python]
pyenv note
GroupBy Note
Deploy Django api on heroku (personal note)
argparse note
Django Note 5
Note: Python
[Personal note] Web page scraping with python3
Ansible Note
Python note
Django Note 1
direnv note
Personal Note Package to install on Anaconda
Django note 3
Django note 2
[Note] RepresenterError