5. ● Understand agenda’s outline
● Know and be familiarized
with some basic concept
about Python programming
language
● Write simple Python
program and
Django-powered web
page/sites
Outcomes
5
9. DJANGO
● A high-level Python web Framework
● Encourages rapid development, clean and pragmatic
design
● ‘For perfectionists with deadlines’
● ‘Focuses and automation and DRY’
● Widely supported and has many deployment options.
9
11. Why use Django?
● The framework has templates, libraries and API designed to
work together for natural growth and connectivity.
● Django suits projects of any size, from small to the biggest
ones.
● Django uses Python which was one of the most popular
programming languages of 2015, and is now the most
popular language for those learning to code.
11
12. Why use Django?
● Django is a more fully featured kit than most of other
frameworks, it contains everything you need to build an app.
● Django adheres to D.R.Y. — Don’t Repeat Yourself —
philosophy. That means that the framework places a premium
on getting the absolute most out of very little code.
12
17. Virtual Environment
- An isolated working copy of Python which allows you
to work on a specific project without worry of
affecting other projects It enables multiple
side-by-side installations of Python, one for each
project.
Install Virtual Environment
Command:
pip3 install virtualenv
17
25. Mysite - Components
25
● manage.py - lets app creator talk through terminal/shell.
● __init__.py - tells file is a python package.
● settings.py - holds the setting configuration of all the app
inside the web app.
● urls.py - has the access and settings of any url used.
● wsgi.py - used to deploy web app to a server.
28. Create Polls App
28
Command:
python manage.py startapp polls
Important Note
Always make sure to check active directory
(before executing code) which is the
<project_name> directory.
30. Polls Directory - Components
30
● admin.py - -allows user to add features in the admin page
● __init__.py - tells file is a python package.
● apps.py - used to configure apps.
● models.py - database layout.
● tests.py - used to app testing.
● views.py - used to display database content.
38. Make Migrations
38
Command:
python manage.py makemigrations polls
Python manage.py migrate
Important Note
Go to settings.py under the <project_name>
and don’t forget to add ‘polls’.
39. Make Migrations(cont.)
39
What’s the use of Migration?
Migrations are Django’s way of propagating
changes you make to your models (adding a field,
deleting a model, etc.)
43. Open Python Shell
43
The Python interactive console (also called the Python
interpreter or Python shell) provides programmers with a
quick way to execute commands and try out or test code
without creating a file.
Command:
python manage.py shell
48. Admin Tool
48
Command:
python manage.py createsuperuser
Python manage.py runserver
Important Note
This command will prompt asking for
username, email address and a password.
57. URLs and Views
57
2 step process to display data:
1. Link urls.py in the main directory to the new urls.py in
the poll directory.
2. Link views.py to the file.
62. HTTP Response
62
Django uses request and response objects to pass state
through the system.
When a page is requested, Django creates an HttpRequest
object that contains metadata about the request. Then Django
loads the appropriate view, passing the HttpRequest as the
first argument to the view function. Each view is responsible
for returning an HttpResponse object.
70. Django Templates
70
Django’s template engine provides a
powerful mini-language for defining the
user-facing layer of your application,
encouraging a clean separation of
application and presentation logic.