LoginSignup
1
1

More than 1 year has passed since last update.

Django で MariaDB の CRUD

Last updated at Posted at 2019-01-22

こちらのプログラムに 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/ にアクセス

city_jan2201.png

Create
city_jan2202.png

Update
city_jan2203.png

Delete
city_jan2204.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1