➕ Adding an Application in Django: Organizing Your Project with Apps
In Django, a project is the entire web application, while an app is a modular component within the project that handles a specific piece of functionality — like a blog, user management, or a store.
Creating and adding apps helps keep your project organized and scalable.
Let’s see how to add an app to your Django project!
️ Step 1: Create a New App
Run this command inside your Django project directory (where manage.py is):
Replace myapp with your app’s name (e.g., blog, shop, accounts).
This creates a new folder named myapp with this structure:
Step 2: Register the App in settings.py
Open your project’s settings.py file and add your app to the INSTALLED_APPS list:
This tells Django to include your app when running commands like migrations or starting the server.
Step 3: Create Views and URLs
Start building your app by defining views in myapp/views.py:
Next, create a urls.py file inside your app folder (myapp/urls.py):
️ Step 4: Include App URLs in the Project
Open your project’s main urls.py file (e.g., myproject/urls.py) and include your app’s URLs:
Step 5: Test Your App
Run the development server:
Visit http://127.0.0.1:8000/ in your browser. You should see:
Summary Checklist
| Step | Command / Action |
|---|---|
| Create app | python manage.py startapp myapp |
| Register app | Add 'myapp' to INSTALLED_APPS |
| Define views | Write functions in myapp/views.py |
| Add app URLs | Create myapp/urls.py with URL patterns |
| Include app URLs | Use include('myapp.urls') in project urls.py |
| Run server and test | python manage.py runserver and visit site |
