Exercises for Django Essential Training Linkedin Course
django-admin startproject name . django-admin startapp home
Model View Template framework MVT
python manage.py runserver
-
Views handle requests and responses
-
Model handles data and how it's stored
-
Template allows us to render DB info to HTML pages; using DTL (Django Template Language) to define pages; Templates -> interpreter -> html (interpreter adds the vars to html)
Migrations use command Migrate
python manage.py migrate
python manage.py createsuperuser
Django uses an ORM; we need class models that will be transformed with migrations to tables; each attribute is a column Classes -> make migrations -> migrations -> database Django's ORM is one of the best Python and SQL ORMs
python manage.py makemigrations
python manage.py shell
from notes.models import Notes mynote = Notes.objects.get(pk='1') mynote.title mynote.text Notes.objects.all() new_note = Notes.objects.create(title="A second note", text="This is a second note") Notes.objects.all() Notes.objects.filter(titlestartswith="My") # ** is __ Notes.objects.filter(titlestartswith="Django") Notes.objects.filter(texticontains='Django') Notes.objects.exclude(texticontains='Django') Notes.objects.filter(text**icontains='Django').exclude(title**icontains='Django')