βοΈ 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 2: Install Django
First, make sure you have Python installed. Then install Django using pip:
pip install django
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
π Step 3: Start the Django Project
Create the Django project using the command:
django-admin startproject config
π§© Step 4: Create Two Django Apps
We will build two apps inside the project:
python manage.py startapp tasks
python manage.py startapp contacts
Now go to config/settings.py and register the apps:
INSTALLED_APPS = [
...
'tasks',
'contacts',
]
π Step 5: Set Up URLs
Update config/urls.py of the main to include both apps:
Create urls.py inside both apps.
π tasks/urls.py
π contacts/urls.py
π‘ Step 6: Create Simple Views
π tasks/views.py
π¨ Step 7: Add Templates
Inside each app, create templates folders like this:
tasks/
βββ templates/
βββ tasks/
βββ index.html
contacts/
βββ templates/
βββ contacts/
βββ index.html
π tasks/templates/tasks/index.html
<!DOCTYPE html>
<html>
<head>
<title>Tasks App</title>
</head>
<body>
<h1>Welcome to the Tasks App</h1>
</body>
</html>
π contacts/templates/contacts/index.html
<!DOCTYPE html>
<html>
<head>
<title>Contacts App</title>
</head>
<body>
<h1>Welcome to the Contacts App</h1>
</body>
</html>
Make sure your settings.py includes:
TEMPLATES = [
{
...
'APP_DIRS': True,
},
]
π Step 8: Run the Project
Run the server:
python manage.py runserver
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
Top comments (0)