This video covers Part 3: Views and Templates of section “Getting Started” from the Django Documentation.
TIMESTAMPS
00:00:00 – Intro
Overview and write additional Views
00:00:50 – Overview
A web-app often contains of many views, e.g. our “Polls” app might have several Views like Index, Vote, Question… Let’s jump back to video 2, the MVT architecture. Views act as “user interface” by displaying data generated from Models via layouts and designs from Templates. So, Django’s Views deliver web pages and other web app content to the user’s internet browser.
00:05:41 – Writing more Views
Make it easier to see and comparing codes
00:08:55 – (optional) Set windows side-by-side
A little tweak to arrange the “Documentation” window to stand side-be-side with the “Code” window. This is to make it more “visual” for us to see and compare between text and code.
More works on Views and Templates
00:10:30 – How it works on internet browser
Checking how the codes working so far. For this we have to “runserver” and then open our “mysite” (http://127.0.0.1:8000 or http://localhost:8000). Now with those opened, we are good to go on with checking “mysite” new codes.
00:16:45 – Adjust index() View
At this step we are adjusting file: polls/views.py and file: polls/urls.py just to see how things work.
00:19:51 – Django’s Template system
Now we do something with the Template by creating sub-directories “Templates” and “Polls” as follow: polls/templates/polls – yes, a sub-directory “polls” within “templates” sub-directory of the “polls” directory. And a file as follow: polls/templates/polls/index.html
00:24:37 – Template namespace
This part explains why we have to create such sub-directories above mentioned. Long story short, imagine your project has 3 apps: polls, voter, topic. Each has its own template named “index.html”. Now putting these “index.html” into separate sub-directories of its app make it ideal for Django to identify and pick the correct “index.html” it needed.
HTML at a glance
00:26:53 – (optional) Little bit basic HTML
Continue with View and Template
00:32:15 – Update index() View to use Template
00:36:19 – A shortcut: render()
00:42:17 – Raising a 404 error
00:48:05 – A shortcut: get_object_or_404()
00:51:10 – Why using get_object_or_404()
00:53:23 – Use the Template system
Working with URL
00:57:17 – Remove hard-coded URLs in templates
In this step of the tutorial we are using the {% url %} template tag to replace the hard-coded URL part in the file: polls/templates/polls/index.html. This technique is to make our app less tightly-coupled and challenging to change URLs in case we have many templates.
01:02:07 – Namespace URL names
This is to help Django differentiate URL names between multiple apps within a project.
Thank you
01:08:52 – Thanks and see you in the next video
More on topic “Django Documentation, Getting Started”
This series can be found on: https://viws.net/category/django4beginners/
You may go to my YouTube Channel for more videos: https://www.youtube.com/channel/UC6JVvyI4k6zzh9vJNhRClRw