๐ Introduction
Bootstrap is a CSS framework used to create:
- Responsive layouts
- Attractive UI
- Mobile-friendly designs
๐ No need to write full CSS manually.
๐ฏ Program Statement
๐ Create a Bootstrap styled responsive page.
๐ง Why Bootstrap?
- Fast UI development
- Mobile responsive
- Predefined components
โ๏ธ Step 1: Create View
๐ File: views.py
๐น Path:
myproject/myapp/views.py
๐น Code:
from django.shortcuts import render
def bootstrap_demo(request):
return render(request, 'bootstrap.html')
โ๏ธ Step 2: URL Mapping
๐ File: urls.py
๐น Path:
myproject/myproject/urls.py
๐น Code:
from django.contrib import admin
from django.urls import path
from myapp import views
urlpatterns = [
path('admin/', admin.site.urls),
path('bootstrap/', views.bootstrap_demo),
]
โ๏ธ Step 3: Create Template
๐ File: bootstrap.html
๐น Path:
myproject/templates/bootstrap.html
๐น Code:
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Page</title>
<!-- Bootstrap CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-4">
<h1 class="text-center text-primary">Bootstrap Responsive Page</h1>
<!-- Row -->
<div class="row mt-4">
<!-- Column 1 -->
<div class="col-md-4">
<div class="card p-3">
<h3>Card 1</h3>
<p>This is a Bootstrap card.</p>
</div>
</div>
<!-- Column 2 -->
<div class="col-md-4">
<div class="card p-3">
<h3>Card 2</h3>
<p>Responsive layout example.</p>
</div>
</div>
<!-- Column 3 -->
<div class="col-md-4">
<div class="card p-3">
<h3>Card 3</h3>
<p>Works on mobile & desktop.</p>
</div>
</div>
</div>
<!-- Button -->
<div class="text-center mt-4">
<button class="btn btn-success">Click Me</button>
</div>
</div>
</body>
</html>
โ๏ธ Step 4: Run Server
python manage.py runserver
๐ Step 5: Output
๐ http://127.0.0.1:8000/bootstrap/
โ Output Features:
- Centered heading
- 3 responsive cards
- Styled button
- Mobile-friendly layout
๐ง How It Works
Bootstrap CDN
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
๐ Loads Bootstrap
Grid System
<div class="row">
<div class="col-md-4">
๐ Creates responsive columns
Card Component
<div class="card p-3">
๐ Styled content box
Button
<button class="btn btn-success">
๐ Pre-styled button
๐ฅ Key Concepts
| Class | Purpose |
|---|---|
container | Page layout |
row | Horizontal grouping |
col-md-4 | Column size |
card | Content box |
btn | Button styling |
โ ๏ธ Common Errors
โ Bootstrap CDN missing
๐ Page will look plain
โ Wrong class name
โ Wrong:
col-4
โ Correct:
col-md-4
โ Not using container
๐ Layout breaks
๐งช Practice Questions
- Add 4 cards instead of 3
- Change button color
- Add image inside card
- Create form using Bootstrap
๐ค Viva Questions & Answers
1. What is Bootstrap?
Bootstrap is a CSS framework for designing responsive web pages.
2. What is CDN?
Content Delivery Network used to load external libraries.
3. What is responsive design?
Design that adapts to different screen sizes.
4. What is grid system?
Bootstrap layout system using rows and columns.
5. What is container class?
It provides proper spacing and alignment.
6. What is card component?
A styled box used to display content.
7. What is col-md-4?
Defines column width for medium screens.
8. What is Bootstrap button class?
btn, btn-primary, btn-success, etc.
9. Why use Bootstrap?
To quickly build responsive UI.
10. Is Bootstrap mobile-friendly?
Yes, it is fully responsive.
๐ Navigation
๐ Next Post: Responsive Navbar and Footer
๐ Back to List: Django Programs (60 Questions with Solutions)
Further Reading
Introduction to Django Framework and its Features
Examples of Array Functions in PHP
Registration Form Using PDO in PHP
Inserting Information from Multiple CheckBox Selection in a Database Table in PHP
- Angular
- ASP.NET
- C
- C#
- C++
- CSS
- Dot Net Framework
- HTML
- IoT
- Java
- JavaScript
- Kotlin
- PHP
- Power Bi
- Python
- Scratch 3.0
- TypeScript
- VB.NET
