Introduction
Django is a robust and versatile Python framework designed to simplify web development. However, how you start your Django project can significantly impact its scalability, maintainability, and performance. This guide provides a comprehensive, step-by-step walkthrough to help you start your Django project the right way, ensuring a solid foundation for success and also tries to explain the project settings and configurations.
Django Project Structure
project structure in django is designed to support the Model-View-Template (MVT) architectural pattern, which is Django’s version of the traditional Model-View-Controller (MVC) framework.
Step 1
I created a folder on my desktop to hold my project and named it "WASTE SOTOR".
Step 2
I create a virtual enviroment, since am on windows i used,
python -m venv env
This creates a folder named env that will store all project-specific Python packages.
Later i had to activate the enviroment using;
env\Scripts\activate
This is an image after i have created and activated the virtual enviroment it created a folder named env.
Step 4
Install Django
I used;
pip install django
This is are the folders that are created after installing Django, they are created on the env folder.
Step 5
Start a project
I used this since i wanted my project to be called waste_sorter ;
django-admin startproject waste_sorter .
This are the project settings and configurations installed.
checking if my project was working
I had to run my project using;
python manage.py runserver
follow the link provide and you should see this;
1.init.py- Makes the folder a Python package .
2.settings.py-Contains all configurations: database, apps, templates, static files, etc.
3.urls.py-Controls which page shows whatand also connects URLs to views.
4.asgi.py-Used for advanced or real-time features and also handles asynchronous requests.
5.wsgi.py-Used to connect Django to a web server and handles normal (synchronous) requests.
Step 6
In this case i started my app and i had 2 of them using the command;
python manage.py startapp app_name
here is an image both apps i created;
short description of the Django App Components
- admin.py: Configuration for the Django admin interface.
- apps.py: Configuration for the app itself.
- models.py: Contains the database models for the app.
- tests.py: Contains tests for the app.
- views.py: Contains the request/response logic for the app.
- migrations/: Contains database migrations for the app. Registered the apps so that my apps could be recognized ,i opened the settings.py and added the apps on the INSTALLED_APPS.
writing views and creating urls
this are the codes that i wrote, i had two since the apps are two;
Step 7 created Urls for both apps
I created new files and made them "urls.py" under each app.
connecting both Urls
This is where i had to join bothof the urls that i created to the main project.
This is what it looked like;
step 8
Adding Templates
This this the folder that shall be kholding all my pages.
Example of one of my pages ;
Step 9
Checking if the project is Running ;
i used the
python manage.py runserver
then follow the link to the browser .For me i got this;
Conclusion
Starting a Django project the right way sets the foundation for a scalable, maintainable, and efficient web application.The images and step-by-step instructions demonstrate how each component fits together, from the initial runserver check to rendering dynamic templates. Whether you’re building a simple app like "WASTE SOROR" or a complex system, Django’s flexibility and structure empower you to focus on functionality rather than boilerplate.
Top comments (0)