DEV Community

Gladys Barasa
Gladys Barasa

Posted on

Day 4 of Django

Introduction

Hello, today is my fourth day of the 20 days of Django and I am excited to share what I did. I worked on my project structure. Stay with me..

Since I already installed django and python, I was set to begin.

Step 1: Create a Django Project

Open a terminal (or PyCharm terminal) and run:
django-admin startproject ProjectTG
cd ProjectTG

Image description

This creates the ProjectTG folder with the main project files.


Step 2: Create Two Django Apps

Let’s name them blog and store

This creates two new folders: blog/ and store/.

Image description

Step 3: Register Apps in settings.py

In ProjectTG/settings.py, add your apps:

Image description

Step 4: Set Up Templates Directory

Still in settings.py, configure Django to look in a templates directory:

Image description

Then, I created this structure:

Image description

Also create templates folders in each app:

Image description

Step 5: Define Views for Each App

Each app will have two views.

blog/views.py

Image description

store/views.py

Image description

Step 6: Create URL Configs

In ProjectTG/urls.py:

Image description

Create blog/urls.py:

Image description

Create store/urls.py:

Image description

Step 7: Add Templates

Create these HTML files:

blog/templates/blog/home.html

Image description

blog/templates/blog/about.html

Image description

store/templates/store/home.html

Image description

store/templates/store/products.html

Image description

Step 9: Run the Server

Start the Django development server:

Image description

Conclusion

The process was a little bit challenging but I am glad I managed

Top comments (0)