🌐 Introduction to Django
📘 What is Django?
Django is a free, open-source, high-level web framework written in Python.
It encourages rapid development and clean, pragmatic design.
Django makes it easier to build web applications by taking care of much of the hassle of web development.
🔧 Why Use Django?
✅ Key Features:
| Feature | Description |
|---|---|
| 🔒 Security | Automatically handles security issues (SQL Injection, CSRF, XSS). |
| ⚙️ Batteries-Included | Comes with everything you need: admin panel, ORM, routing, authentication. |
| 🚀 Fast Development | Build web apps quickly with less code. |
| 🔁 Reusable Code | Modular structure: break code into apps and reuse them. |
| 🧩 Scalable | Used by high-traffic sites like Instagram, Pinterest. |
| 🛡️ Robust Admin Interface | Auto-generated dashboard to manage content easily. |
🏗️ Django Architecture: MVT
Django follows the Model-View-Template (MVT) pattern:
User <--> View (Python Code) <--> Model (Database) <--> Template (HTML)| Component | Role |
|---|---|
| Model | Manages data and database (tables, fields). |
| View | Handles request and response logic. |
| Template | Displays HTML content using Django Template Language. |
🚀 How Django Works (Basic Flow)
- User types a URL in the browser.
- URL Dispatcher finds the correct view function.
- View fetches data using Model.
- Passes data to the Template.
- Template renders the page.
- Response goes back to the user.
📦 Installing Django
✅ Requirements:
- Python 3.x
- pip (Python package installer)
🔧 Installation:
pip install django✅ Verify Django Version:
django-admin --version🛠️ Creating Your First Django Project
django-admin startproject mysite
cd mysite
python manage.py runserverVisit: http://127.0.0.1:8000/ ➡️ You’ll see the Django welcome page 🎉
🧩 Creating a Django App
Apps are reusable modules. For example: blog, shop, accounts, etc.
python manage.py startapp blogThen, add the app to INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
'blog',
...
]📄 Django Project Structure
mysite/
├── manage.py
├── mysite/
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── blog/
│ ├── models.py
│ ├── views.py
│ └── templates/🔗 Creating Your First URL & View
Step 1: Add a view in blog/views.py
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello Django!")Step 2: Add URL in blog/urls.py (create if not exists)
from django.urls import path
from . import views
urlpatterns = [
path('', views.home),
]Step 3: Include in main urls.py
from django.urls import include, path
urlpatterns = [
path('', include('blog.urls')),
]📊 Django Admin Panel
Django provides a built-in admin dashboard to manage models.
Steps:
python manage.py createsuperuserGo to http://127.0.0.1:8000/admin
Login ➡️ Explore Admin Panel!
🔚 Summary
- Django is a powerful, scalable, secure Python framework.
- It follows MVT architecture.
- It includes everything you need to build web apps fast.
- Ideal for blogs, CMS, ecommerce, dashboards, APIs, social apps and more.
Would you like to proceed with:
- 🔄 Django CRUD Tutorial
- 🔌 Django REST API
- 🛒 Django + Vue eCommerce project
- 🧠 Django with MySQL/PostgreSQL
Let me know what you want to build!
