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?