Python & Django
Introduction
Python is one of the most popular and versatile programming languages, widely used for web development, automation, data science, AI, and more. In web development, Django and Flask are two of the most widely used frameworks that simplify backend development.
Django is a full-stack web framework that follows the "batteries-included" philosophy, providing built-in tools for authentication, database management, and security.
Flask is a lightweight, minimalistic web framework that provides flexibility, allowing developers to build scalable web applications with custom features.
Why Choose Python for Web Development?
Easy to Learn – Simple and readable syntax.
Huge Ecosystem – Libraries for web, AI, ML, data science, etc.
Fast Development – Django and Flask reduce development time.
Scalability – Used by companies like Instagram, Pinterest, and Reddit.
Security – Django provides built-in security features.
Django – The Full-Featured Web Framework
1️⃣ Installing Django
Install Django using pip:
Check if Django is installed:
2️⃣ Creating a Django Project
Visit http://127.0.0.1:8000/ in your browser to see your Django project running!
3️⃣ Django Project Structure
4️⃣ Creating a Django App
Register the app in settings.py
:
5️⃣ Django Models – Database Handling
Django uses ORM (Object-Relational Mapping) for database management.
Define a Model in models.py
Apply Migrations to Create the Database Table
Create a Superuser for Admin Panel
Visit http://127.0.0.1:8000/admin/ to manage the database using Django’s built-in admin panel.
6️⃣ Django Views & Routing
Define a View in views.py
Define a URL Pattern in urls.py
Visit: http://127.0.0.1:8000/
Output: "Hello, Django!
7️⃣ Django Templates – Rendering HTML
Create a Template (templates/home.html
)
Modify views.py
to Use Templates
Now your Django app can render HTML pages dynamically!
Last updated
Was this helpful?