DEV Community

zipporahmutanu04
zipporahmutanu04

Posted on

DAY 4: Getting started with Django: Build your first project step by step

✍️ By ZeddyEem

🌱 Introduction
If you're just getting started with Django, welcome! This guide will walk you through everything you need to build your first simple Django project β€” from installation to creating your own HTML templates and apps.

We’ll build a simple project called Config, which has two apps:

βœ… tasks – for managing daily to-do items.

βœ… contacts – for saving personal or professional contacts.

Step 1:Check Versions
Image description

βš™οΈ Step 2: Install Django
First, make sure you have Python installed. Then install Django using pip:
pip install django

Image description
You can also create a virtual environment for better project management:

python -m venv env
source env/bin/activate    # On Windows: env\Scripts\activate
pip install django
Enter fullscreen mode Exit fullscreen mode

Image description

πŸš€ Step 3: Start the Django Project
Create the Django project using the command:

django-admin startproject config

Image description

🧩 Step 4: Create Two Django Apps
We will build two apps inside the project:

python manage.py startapp tasks
python manage.py startapp contacts
Enter fullscreen mode Exit fullscreen mode

Image description
Now go to config/settings.py and register the apps:

INSTALLED_APPS = [
...
'tasks',
'contacts',
]

Image description

🌐 Step 5: Set Up URLs
Update config/urls.py of the main to include both apps:

Image description
Create urls.py inside both apps.

πŸ“ tasks/urls.py

Image description

πŸ“ contacts/urls.py

Image description

πŸ’‘ Step 6: Create Simple Views
πŸ“„ tasks/views.py

Image description

contacts/views.py
Image description

🎨 Step 7: Add Templates
Inside each app, create templates folders like this:

tasks/
└── templates/
    └── tasks/
        └── index.html

contacts/
└── templates/
    └── contacts/
        └── index.html
Enter fullscreen mode Exit fullscreen mode

πŸ“„ tasks/templates/tasks/index.html

<!DOCTYPE html>
<html>
<head>
    <title>Tasks App</title>
</head>
<body>
    <h1>Welcome to the Tasks App</h1>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

πŸ“„ contacts/templates/contacts/index.html

<!DOCTYPE html>
<html>
<head>
    <title>Contacts App</title>
</head>
<body>
    <h1>Welcome to the Contacts App</h1>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Make sure your settings.py includes:

TEMPLATES = [
    {
        ...
        'APP_DIRS': True,
    },
]
Enter fullscreen mode Exit fullscreen mode

πŸ›  Step 8: Run the Project
Run the server:
python manage.py runserver

Image description
Visit:

http://127.0.0.1:8000/tasks/ – View your tasks app

http://127.0.0.1:8000/contacts/ – View your contacts app

🎁 Final Thoughts
Django is powerful, but the best way to learn is to start small. With this basic setup, you now have two working apps in a Django project β€” fully connected with HTML templates and views.

Next up, you can expand it into a complete productivity tool!

πŸ’¬ Let’s Connect!
Got stuck? Have questions? Drop them in the comments or DM me.
Let’s build the future of tech, one line at a time.

πŸ”— Useful Commands Summary

# Create project and apps
django-admin startproject config
python manage.py startapp tasks
python manage.py startapp contacts

# Run server
python manage.py runserver
Enter fullscreen mode Exit fullscreen mode

Top comments (0)