Python & Django Beginner Level Course
1. Introduction to Python
Explanation:
Python is a high-level, interpreted programming language known for its simplicity and readability. It
is widely used in web development, data science, automation, and more. Python uses indentation to
define blocks of code, which makes the code visually organized.
Exercise:
Install Python and write your first Python script that prints 'Hello, World!'.
Review Questions:
- What is Python and why is it popular?
- How do you print a message in Python?
- What does indentation mean in Python?
2. Variables, Data Types, and Operators
Explanation:
Variables are used to store data in a program. Data types include integers, floats (decimal
numbers), strings (text), booleans (True/False), lists, and more. Operators are symbols like +, -, *, /
used to perform operations on variables and values.
Exercise:
Create variables for your name (string), age (int), and GPA (float). Print them with appropriate
labels.
Review Questions:
- What is a variable in Python?
- List three common data types and give examples.
- What are arithmetic operators in Python?
3. Control Structures (if, for, while)
Explanation:
Control structures allow you to control the flow of your program. 'if' statements let you make
decisions. 'for' loops let you repeat actions a fixed number of times. 'while' loops continue as long as
a condition is true.
Exercise:
Write a program that checks if a number is positive, negative, or zero using if-else.
Review Questions:
- What is an if statement used for?
- How does a for loop work in Python?
- When would you use a while loop?
4. Functions and Modules
Explanation:
Functions let you group code into reusable blocks. You define a function using the 'def' keyword.
Modules are files containing Python code (functions, variables) you can import into other files to
reuse.
Exercise:
Write a function that takes two numbers and returns their sum. Call this function with two numbers.
Review Questions:
- How do you define a function in Python?
- What is a module?
- Why use functions in programming?
5. Introduction to Django
Explanation:
Django is a high-level Python web framework that encourages rapid development and clean,
pragmatic design. It helps you build web applications quickly by providing ready-made components.
Exercise:
Install Django using pip and check the version using 'django-admin --version'.
Review Questions:
- What is Django used for?
- How do you install Django?
- What is a web framework?
6. Setting up a Django Project
Explanation:
To start using Django, you need to create a project using 'django-admin startproject projectname'.
This sets up the directory structure and necessary files for a Django app.
Exercise:
Create a Django project named 'myfirstproject'. Run the server and visit localhost in your browser.
Review Questions:
- How do you create a Django project?
- What command runs the Django development server?
- What is the purpose of the 'manage.py' file?
7. Models, Views, Templates (MVT) Overview
Explanation:
Django follows the MVT pattern. Models define your data structure. Views handle business logic.
Templates define how data is presented to the user (HTML files). This separation helps manage
large applications.
Exercise:
Create a basic model for a 'Book' with fields: title and author. Show how a view can return a simple
message.
Review Questions:
- What does MVT stand for in Django?
- What is the role of each MVT component?
- How is Django's MVT different from MVC?
Beginner Level Project: Simple Blog
Create a simple blog website using Django. The blog should have the following features:
- Home page that displays 'Welcome to My Blog'
- A model for BlogPost with fields: title, content, and date_created
- A view that returns a list of all blog posts
- A basic template to render the blog posts
This project will reinforce your understanding of Python, Django setup, models, views, and
templates.