Class Based View CRUD Django with BootstrapTemplate
Basic Class Based View CRUD Django with Bootstrap Template. Django Official docs here.
Step 1: Preparation, Create Django Project, Initial Migration
install virtualenv: pip install virtualenv
create virtualenv: virtualenv venv
start virtualenv: venv/Scripts/activate
install Django in virtualenv: pip install django
Create Django: django-admin startproject myproject
Go to myproject folder: cd myproject
Initial Migration: python manage.py migrate
Step 2: Create Django Apps
Create apps: python manage.py startapp myapp
Add myapp to INSTALLED_APPS in myproject/settings.py
Step 3: Set up Templates Folder
Create folder templates in myapp
Add template directory in TEMPLATES parameter in myproject/settings.py
os.path.join(BASE_DIR, 'myapp', 'templates')
Step 4: Create Model in myapp, Makemigrations and Migrate
Add Book Model in myapp/models.py
Make migrations: python manage.py makemigrations
Migrate: python manage.py migrate
Step 5: Create HTML Files in myapp/templates Folder
Create bootstrap base, create myapp/templates/base.html CDN Bootstrap.
Create book-list template, myapp/templates/book-list.html
Create book-create template, myapp/templates/book-create.html
Create book-detail template, myapp/templates/book-detail.html
Create book-update template, myapp/templates/book-update.html
Create book-delete template, myapp/templates/book-delete.html
Step 6: Create Class Based View in myapp/views.py
Update myapp/views.py. Add Class Based View method.
Step 7. Setup URLs in myapp and myproject Folder
Create myapp/urls.py
Update myproject/urls.py
Step 8: Run Server and Testing
Run Server: python manage.py runserver
Testing: http://127.0.0.1:8000/book-list
Try to Add, View Detail, Update, and Delete
Summarized Section
Step 1: Preparation, Create Django Project, Initial Migration
install virtualenv: pip install virtualenv
create virtualenv: virtualenv venv
start virtualenv: venv/Scripts/activate
install Django in virtualenv: pip install django
Create Django: django-admin startproject myproject
Go to myproject folder: cd myproject
Initial Migration: python manage.py migrate
Step 2: Create Django Apps
Create apps: python manage.py startapp myapp
Add myapp to INSTALLED_APPS in myproject/settings.py
Step 3: Set up Templates Folder
Create folder templates in myapp
Add template directory in TEMPLATES parameter in myproject/settings.py
os.path.join(BASE_DIR, 'myapp', 'templates')
Step 4: Create Model in myapp, Makemigrations and Migrate
Add Book Model in myapp/models.py
Make migrations: python manage.py makemigrations
Migrate: python manage.py migrate
Step 5: Create HTML Files in myapp/templates Folder
Create bootstrap base, create myapp/templates/base.html
Create book-list.html, book-create.html, book-detail.html, book-update.html, book-delete.html
Step 6: Create Class Based View myapp/views.py
Update myapp/views.py. Add Class Based View method
Step 7: Setup URLs in myapp and myproject folder
Create myapp/urls.py
Update myproject/urls.py, include myapp/urls.py
Step 8: Run Server and Testing
Run Server: python manage.py runserver
Testing: http://127.0.0.1:8000/book-list