Day 4: Building My First Django Project with Linked Apps (And Making It Look Good Too)

Todays Task

Use Django’s project + app architecture
Link two apps: library and members
Display templates for each

✅ Step 1: Installed virtualenv (if not already there) using the command

sudo apt install python3-venv

🗂️ Step 2: Cr…


This content originally appeared on DEV Community and was authored by Zabby

Todays Task

  • Use Django’s project + app architecture
  • Link two apps: library and members
  • Display templates for each

✅ Step 1: Installed virtualenv (if not already there) using the command

sudo apt install python3-venv

🗂️ Step 2: Created a virtual environment in my project folder

python3 -m venv venv

This created a venv/ folder containing an isolated Python environment complete with its own pip, python, and site-packages.

🚀 Step 3: Activated the virtual environment

source venv/bin/activate

Image description

Once activated, my terminal prompt changed (it showed (venv)), and any packages I installed from that point forward were isolated to the project.
To deactivate it run the command: deactivate

To Install Django you run the command:

python -m pip install django             

Image description

📁 Step One: Starting the Django Project.

django-admin startproject community
cd community

I saw this structure:

community/
    manage.py
    my_project/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

📁 Step 2: Created Django Apps

Installed the required django apps i went with library & members.

python manage.py startapp library
python manage.py startapp members

Image description

Step 3: Creating Models That Talk to Each Other

library/models.py

class Book(models.Model):
    title = models.CharField(max_length=100)
    author = models.CharField(max_length=100)

members/models.py:

from library.models import Book

class Member(models.Model):
    name = models.CharField(max_length=100)
    borrowed_book = models.ForeignKey(Book, on_delete=models.CASCADE)

I ran migrations to apply these changes:

python manage.py makemigrations
python manage.py migrate

🧠 Step 4: Simple Views

Each app got its own view to send data to the templates.

library/views.py:

def book_list(request):
    books = Book.objects.all()
    return render(request, 'library/books.html', {'books': books})

members/views.py:

def member_list(request):
    members = Member.objects.all()
    return render(request, 'members/members.html', {'members': members})

🖼️ Step 5: Linking Templates with Style

Both apps got their own templates directory. I used Bootstrap and a light CSS gradient background to make them feel cleaner and more polished.

Here’s a peek at books.html:

<body style="background: linear-gradient(to bottom right, #f2f2f2, #e6f7ff);">
  <div class="container mt-5 bg-white p-4 rounded shadow">
    <h2>📚 Library Books</h2>
    <ul>
      {% for book in books %}
        <li>{{ book.title }} by {{ book.author }}</li>
      {% endfor %}
    </ul>
    <a href="/members/">View Members</a>
  </div>
</body>

Same idea applied to members.html, with a flipped color scheme to visually separate them.

🌐 Step 6: URLs That Connect It All

Each app got its own urls.py, which I included in the main community/urls.py:

urlpatterns = [
    path('library/', include('library.urls')),
    path('members/', include('members.urls')),
]

Now I could browse:

/library/ to see the books

/members/ to view who borrowed what

💡 What I Learned
Django's app structure scales cleanly—even for a beginner

Connecting models across apps is smooth once you understand ForeignKey

Styling with Bootstrap + gradients makes Django feel like more than just a backend toy

Always create urls.py for each app before including them in project/urls.py (yes, I hit that error 😅)


This content originally appeared on DEV Community and was authored by Zabby


Print Share Comment Cite Upload Translate Updates
APA

Zabby | Sciencx (2025-06-30T16:37:35+00:00) Day 4: Building My First Django Project with Linked Apps (And Making It Look Good Too). Retrieved from https://www.scien.cx/2025/06/30/day-4-building-my-first-django-project-with-linked-apps-and-making-it-look-good-too/

MLA
" » Day 4: Building My First Django Project with Linked Apps (And Making It Look Good Too)." Zabby | Sciencx - Monday June 30, 2025, https://www.scien.cx/2025/06/30/day-4-building-my-first-django-project-with-linked-apps-and-making-it-look-good-too/
HARVARD
Zabby | Sciencx Monday June 30, 2025 » Day 4: Building My First Django Project with Linked Apps (And Making It Look Good Too)., viewed ,<https://www.scien.cx/2025/06/30/day-4-building-my-first-django-project-with-linked-apps-and-making-it-look-good-too/>
VANCOUVER
Zabby | Sciencx - » Day 4: Building My First Django Project with Linked Apps (And Making It Look Good Too). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/06/30/day-4-building-my-first-django-project-with-linked-apps-and-making-it-look-good-too/
CHICAGO
" » Day 4: Building My First Django Project with Linked Apps (And Making It Look Good Too)." Zabby | Sciencx - Accessed . https://www.scien.cx/2025/06/30/day-4-building-my-first-django-project-with-linked-apps-and-making-it-look-good-too/
IEEE
" » Day 4: Building My First Django Project with Linked Apps (And Making It Look Good Too)." Zabby | Sciencx [Online]. Available: https://www.scien.cx/2025/06/30/day-4-building-my-first-django-project-with-linked-apps-and-making-it-look-good-too/. [Accessed: ]
rf:citation
» Day 4: Building My First Django Project with Linked Apps (And Making It Look Good Too) | Zabby | Sciencx | https://www.scien.cx/2025/06/30/day-4-building-my-first-django-project-with-linked-apps-and-making-it-look-good-too/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.