こちらのプログラムに CRUD の機能をつけました。
Django で MariaDB のテーブルを表示
Django のコードはこちらです。
ekzemplaro/django_mariadb_city
アプリの構造
$ tree city -I '_*'
city
├── admin.py
├── apps.py
├── forms.py
├── migrations
│ └── 0001_initial.py
├── models.py
├── static
│ └── city
│ └── css
│ └── city.css
├── templates
│ └── city
│ ├── create.html
│ ├── delete.html
│ ├── edit.html
│ └── index.html
├── tests.py
├── urls.py
└── views.py
1) GitHub からクローン
git clone https://github.com/ekzemplaro/django_mariadb_city
2) 必要なライブラリーのインストール
sudo pip3 install django-environ
3) .env の作成
proj01/.env
DB_USER="django"
DB_PASSWORD="tiger123"
DB_NAME="django_city"
4) データベースの作成
ユーザー django
パスワード tiger123
データベース django_city
mysql> create database django_city;
mysql> grant all on django_city.* to django@localhost;
5) マイグレーション
cd prog01
python manage.py migrate
6) データをデータベースに入れる
cd data
./go_restore.sh
7) 開発サーバーを起動
python manage.py runserver
8) http://127.0.0.1:8000/city/ にアクセス