Django

Develop a Simple Portfolio Site using Templates and Static Resources

๐Ÿ“Œ Introduction

A portfolio website is used to present:

  • Personal details
  • Skills
  • Projects
  • Contact information

In Django, we can build a simple portfolio site using:

  • views
  • URLs
  • templates
  • static CSS
  • static images

This program is useful as a mini project for practical exams and lab files.


๐ŸŽฏ Program Statement

๐Ÿ‘‰ Develop a simple portfolio site using templates and static resources.


๐Ÿง  Features of the Portfolio Site

This portfolio site will include:

  • Home page
  • About page
  • Projects page
  • Contact page
  • Navigation bar
  • Footer
  • CSS styling
  • Profile image

โš™๏ธ Step 1: Project Structure

Create the following structure:

myproject/
โ”‚
โ”œโ”€โ”€ manage.py
โ”œโ”€โ”€ myproject/
โ”‚ โ”œโ”€โ”€ settings.py
โ”‚ โ”œโ”€โ”€ urls.py
โ”‚
โ”œโ”€โ”€ myapp/
โ”‚ โ”œโ”€โ”€ views.py
โ”‚
โ”œโ”€โ”€ templates/
โ”‚ โ”œโ”€โ”€ base.html
โ”‚ โ”œโ”€โ”€ home.html
โ”‚ โ”œโ”€โ”€ about.html
โ”‚ โ”œโ”€โ”€ projects.html
โ”‚ โ””โ”€โ”€ contact.html
โ”‚
โ””โ”€โ”€ static/
โ”œโ”€โ”€ css/
โ”‚ โ””โ”€โ”€ style.css
โ””โ”€โ”€ images/
โ””โ”€โ”€ profile.jpg

โš™๏ธ Step 2: Configure Static Files and Templates

๐Ÿ“ File: settings.py

๐Ÿ”น Path:

myproject/myproject/settings.py

๐Ÿ”น Code:

import os

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',
]

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

STATIC_URL = '/static/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]

โš™๏ธ Step 3: Create Views

๐Ÿ“ File: views.py

๐Ÿ”น Path:

myproject/myapp/views.py

๐Ÿ”น Code:

from django.shortcuts import render

def home(request):
return render(request, 'home.html')

def about(request):
return render(request, 'about.html')

def projects(request):
project_list = [
{"title": "Student Management System", "tech": "Django, MySQL"},
{"title": "Online Quiz App", "tech": "Python, Django"},
{"title": "Portfolio Website", "tech": "Django, HTML, CSS"},
]
return render(request, 'projects.html', {'projects': project_list})

def contact(request):
return render(request, 'contact.html')

โš™๏ธ Step 4: 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('', views.home, name='home'),
path('about/', views.about, name='about'),
path('projects/', views.projects, name='projects'),
path('contact/', views.contact, name='contact'),
]

โš™๏ธ Step 5: Create CSS File

๐Ÿ“ File: style.css

๐Ÿ”น Path:

myproject/static/css/style.css

๐Ÿ”น Code:

body {
margin: 0;
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}

.navbar {
background-color: #222;
padding: 15px;
text-align: center;
}

.navbar a {
color: white;
text-decoration: none;
margin: 15px;
font-weight: bold;
}

.navbar a:hover {
color: yellow;
}

.container {
width: 80%;
margin: auto;
padding: 30px;
text-align: center;
}

.profile-img {
width: 180px;
height: 180px;
border-radius: 50%;
margin-top: 20px;
border: 4px solid #333;
}

.card {
background: white;
padding: 20px;
margin: 15px auto;
width: 70%;
border-radius: 10px;
box-shadow: 0 0 10px gray;
}

.footer {
background-color: #222;
color: white;
text-align: center;
padding: 12px;
margin-top: 30px;
}

@media screen and (max-width: 768px) {
.container {
width: 95%;
}

.card {
width: 90%;
}

.navbar a {
display: block;
margin: 10px 0;
}
}

โš™๏ธ Step 6: Add Profile Image

๐Ÿ“ File: profile.jpg

๐Ÿ”น Path:

myproject/static/images/profile.jpg

๐Ÿ‘‰ Add any image and rename it as profile.jpg


โš™๏ธ Step 7: Create Base Template

๐Ÿ“ File: base.html

๐Ÿ”น Path:

myproject/templates/base.html

๐Ÿ”น Code:

{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>Portfolio Site</title>
<link rel="stylesheet" href="{% static 'css/style.css' %}">
</head>
<body>

<div class="navbar">
<a href="{% url 'home' %}">Home</a>
<a href="{% url 'about' %}">About</a>
<a href="{% url 'projects' %}">Projects</a>
<a href="{% url 'contact' %}">Contact</a>
</div>

<div class="container">
{% block content %}
{% endblock %}
</div>

<div class="footer">
<p>ยฉ 2026 My Portfolio | All Rights Reserved</p>
</div>

</body>
</html>

โš™๏ธ Step 8: Create Home Page Template

๐Ÿ“ File: home.html

๐Ÿ”น Path:

myproject/templates/home.html

๐Ÿ”น Code:

{% extends 'base.html' %}
{% load static %}

{% block content %}
<h1>Welcome to My Portfolio</h1>
<img src="{% static 'images/profile.jpg' %}" alt="Profile Image" class="profile-img">
<p>Hello! I am a web developer and Python enthusiast.</p>
{% endblock %}

โš™๏ธ Step 9: Create About Page Template

๐Ÿ“ File: about.html

๐Ÿ”น Path:

myproject/templates/about.html

๐Ÿ”น Code:

{% extends 'base.html' %}

{% block content %}
    <h1>About Me</h1>
    <div class="card">
        <p>My name is Juhi. I am interested in Python, Django, Full Stack Development, and Cloud Computing.</p>
    </div>
{% endblock %}

โš™๏ธ Step 10: Create Projects Page Template

๐Ÿ“ File: projects.html

๐Ÿ”น Path:

myproject/templates/projects.html

๐Ÿ”น Code:

{% extends 'base.html' %}

{% block content %}
<h1>My Projects</h1>

{% for p in projects %}
<div class="card">
<h3>{{ p.title }}</h3>
<p>Technology Used: {{ p.tech }}</p>
</div>
{% endfor %}
{% endblock %}

โš™๏ธ Step 11: Create Contact Page Template

๐Ÿ“ File: contact.html

๐Ÿ”น Path:

myproject/templates/contact.html

๐Ÿ”น Code:

{% extends 'base.html' %}

{% block content %}
    <h1>Contact Me</h1>
    <div class="card">
        <p>Email: example@gmail.com</p>
        <p>Phone: +91-9999999999</p>
    </div>
{% endblock %}

โš™๏ธ Step 12: Run Server

python manage.py runserver

๐ŸŒ Step 13: Output

Open the following URLs:

  • Home โ†’ http://127.0.0.1:8000/
  • About โ†’ http://127.0.0.1:8000/about/
  • Projects โ†’ http://127.0.0.1:8000/projects/
  • Contact โ†’ http://127.0.0.1:8000/contact/

โœ… Expected Output:

  • Styled portfolio site
  • Profile image on home page
  • About information
  • Projects displayed dynamically
  • Contact details
  • Responsive navbar and footer

๐Ÿง  How It Works

  1. urls.py maps each URL to a view
  2. views.py renders the correct template
  3. base.html provides common layout
  4. Child templates extend base.html
  5. style.css provides styling
  6. profile.jpg is loaded from static folder

โš ๏ธ Common Errors

โŒ CSS not loading

Check:

  • {% load static %} is present
  • Correct path:
{% static 'css/style.css' %}

โŒ Image not displaying

Check:

  • Image placed in:
static/images/profile.jpg

โŒ Reverse URL error

Ensure URL names are added correctly:

name='home'

โŒ Template not found

Make sure all templates are inside:

myproject/templates/

๐Ÿงช Practice Questions

  1. Add a Skills page
  2. Add social media links in footer
  3. Add more projects in list
  4. Add a background image to home page
  5. Use Bootstrap instead of plain CSS

๐ŸŽค Viva Questions & Answers

1. What is a portfolio website?

A portfolio website is a personal site used to present information such as profile, skills, projects, and contact details. It is useful for students and professionals to showcase their work.

2. Why do we use base.html in a portfolio site?

base.html contains the common layout like navbar and footer, which can be reused across multiple pages. This reduces code duplication and makes maintenance easier.

3. What is the purpose of static files in this program?

Static files are used for CSS and images. They help improve design, styling, and overall presentation of the portfolio website.

4. Why do we use {% extends %} in child templates?

{% extends %} allows a child template to inherit the layout of a base template. It ensures consistency across pages.

5. What is {% block content %} used for?

It defines a replaceable section in the base template where child templates insert their own content.

6. Why is the projects page dynamic in this program?

The projects page receives a list of project dictionaries from the view and displays them in a loop. So the content can be changed without editing HTML manually.

7. What is the role of views.py in this project?

views.py handles requests and decides which template should be rendered. It can also send dynamic data to templates.

8. What is the use of {% url %} in navbar links?

{% url %} creates dynamic links based on URL names. It avoids hardcoding paths and makes navigation safer.

9. How is responsiveness added in this program?

Responsiveness is added through CSS media queries. This makes the layout adapt to mobile and smaller screens.

10. Why is this program important for students?

It combines multiple Django concepts such as templates, static files, inheritance, loops, and navigation. So it serves as a good mini project for exams and portfolio building.


๐Ÿ”— Navigation

๐Ÿ‘‰ Next Post: Forms Section Begins
๐Ÿ‘‰ Back to List: Django Programs (60 Questions with Solutions)


Further Reading

Introduction to Django Framework and its Features

Django Practice Exercise

Examples of Array Functions in PHP

Basic Programs in PHP

Registration Form Using PDO in PHP

Inserting Information from Multiple CheckBox Selection in a Database Table in PHP

programmingempire

princites.com

You may also like...

Leave a Reply

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