Django project structure helps organize your web app files clearly. It makes your code easy to find and manage.
0
0
Django project structure walkthrough
Introduction
When starting a new Django web application.
When you want to understand where to put your code and templates.
When you need to add new features like apps or static files.
When debugging or updating your Django project.
When collaborating with others on a Django project.
Syntax
Django
myproject/ # Root folder of your project manage.py # Command-line tool to run tasks myproject/ # Main project folder __init__.py # Marks this as a Python package settings.py # Configuration settings urls.py # URL routing for the project asgi.py # ASGI server entry point wsgi.py # WSGI server entry point app1/ # A Django app folder migrations/ # Database migrations __init__.py admin.py # Admin site settings apps.py # App configuration models.py # Data models tests.py # Tests for app views.py # Views (logic for pages) templates/ # HTML templates static/ # Static files like CSS, JS, images
The manage.py file helps you run commands like starting the server or making migrations.
Each app is a smaller part of your project that does one job, like handling users or blog posts.
Examples
This shows a project with one app called
blog. Templates for the blog are inside the app folder.Django
myproject/
manage.py
myproject/
settings.py
urls.py
blog/
models.py
views.py
templates/
blog/
post_list.htmlHere, static files like CSS are stored in a separate
static folder at the project root.Django
myproject/
manage.py
myproject/
settings.py
urls.py
users/
models.py
views.py
static/
css/
style.cssSample Program
This is a simple Django project with one app called polls. It has folders for templates and static files outside the app folder for shared use.
Django
myproject/
manage.py
myproject/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py
polls/
__init__.py
admin.py
apps.py
migrations/
__init__.py
models.py
tests.py
views.py
templates/
base.html
static/
css/
main.cssOutputSuccess
Important Notes
Always keep your apps focused on one task to keep your project organized.
Use the templates folder for HTML files and static for CSS, JavaScript, and images.
Remember to add your apps to INSTALLED_APPS in settings.py to activate them.
Summary
Django projects have a clear folder structure to organize code and files.
manage.py helps run commands for your project.
Apps are smaller parts of the project, each with its own files.