こちらのプログラムに 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
- GitHub からクローン
git clone https://github.com/ekzemplaro/django_mariadb_city
- 必要なライブラリーのインストール
sudo pip3 install django-environ
- .env の作成
proj01/.env
DB_USER="django"
DB_PASSWORD="tiger123"
DB_NAME="django_city"
- データベースの作成
ユーザー django
パスワード tiger123
データベース django_city
mysql> create database django_city;
mysql> grant all on django_city.* to django@localhost;
- マイグレーション
cd prog01
python manage.py migrate
- データをデータベースに入れる
cd data
./go_restore.sh
- 開発サーバーを起動
python manage.py runserver