HomePYTHONDJANGODjango Introduction

Django Introduction

🌐 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:

FeatureDescription
🔒 SecurityAutomatically handles security issues (SQL Injection, CSRF, XSS).
⚙️ Batteries-IncludedComes with everything you need: admin panel, ORM, routing, authentication.
🚀 Fast DevelopmentBuild web apps quickly with less code.
🔁 Reusable CodeModular structure: break code into apps and reuse them.
🧩 ScalableUsed by high-traffic sites like Instagram, Pinterest.
🛡️ Robust Admin InterfaceAuto-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)
ComponentRole
ModelManages data and database (tables, fields).
ViewHandles request and response logic.
TemplateDisplays HTML content using Django Template Language.

🚀 How Django Works (Basic Flow)

  1. User types a URL in the browser.
  2. URL Dispatcher finds the correct view function.
  3. View fetches data using Model.
  4. Passes data to the Template.
  5. Template renders the page.
  6. 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 runserver

Visit: 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 blog

Then, 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 createsuperuser

Go 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!

Share: 

No comments yet! You be the first to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *