How to Create an App in Django
Last Updated :
13 Nov, 2025
Django apps are separate modules that handle specific features in a web project, helping keep code clean and organized.
- Each application is responsible for a particular function, such as handling data, managing pages, or facilitating routing.
- A Django project works as the main setup that brings multiple apps together.
- Every app contains its own models, views, templates, and URLs.
- Example apps include: a Posts app for creating and showing blog articles, a Comments app for adding and moderating user comments, and a Users app for login, signup, and profile features.
Pre-installed apps in Django
Django includes several pre-installed apps for convenience. To view them, check the INSTALLED_APPS section in settings.py. The apps listed there are provided by Django to simplify development.
pre-installed apps in settings.pyBefore creating apps in a Django project, ensure the project folder exists. If it doesn’t, create it using the following command:
django-admin startproject project_name
Steps to create apps in django
Step 1: Navigate to the Project Directory
Open the terminal and navigate to the root directory of the Django project, where the manage.py file is located:
cd project_name
Step 2: Create a New App
Create a Django app with the following command:
python manage.py startapp projectApp
This will generate a directory structure like:
File structure of the projectStep 3: Register the App in Project's settings.py
Open project_name/settings.py and add app to the INSTALLED_APPS list:
Python
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'projectApp' # Add app here
]
Step 4: Include App URLs in Project URLs
After creating the app, connect its URLs to the main project so Django can route requests to the app’s views
In urls.py of the main project directory (project_name/projectApp), import:
from django.urls import include
In the urlpatterns list, add the following line to include the app’s URLs:
Python
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls), # Admin panel URL
path('', include("projectApp.urls")), # Include app URLs
]
Step 5: Create urls.py in App
The app requires its own urls.py to define view routes. If it doesn’t exist, create it inside the projectApp directory:
Python
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
Step 6: Create a View
In projectApp/views.py, define a view that will return a simple response:
Python
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, Geeks! Welcome to your first Django app.")
Optional: Update ROOT_URLCONF
By default, Django sets ROOT_URLCONF = 'project.urls' in settings.py as the main URL routing file. It’s recommended to leave this setting unchanged unless advanced routing is required.
For direct app routing:
ROOT_URLCONF = 'app.urls'
Step 7: Run the Development Server
python manage.py runserver
Visit:
http://127.0.0.1:8000/
Snapshot of localhostDjango App Features
Feature | Description |
|---|
Modularity | Apps are loosely coupled and independently developed. |
|---|
Reusability | Apps are reusable across projects. |
|---|
Collaboration | Teams can work independently on separate apps. |
|---|
Organization | Maintains clean, organized, and manageable code. |
|---|
Built-in Features | Django offers tools like admin, middleware, etc., to accelerate development. |
|---|
Related Posts:
Which command creates a new Django app inside an existing project?
-
django-admin startproject appName
-
python manage.py startapp appName
-
python manage.py makeapp appName
-
django-admin createapp appName
Explanation:
python manage.py startapp appName command generates the standard Django app directory structure under the project.
After creating an app what change is required for Django to recognize the app?
-
Add the app name to INSTALLED_APPS in settings.py
-
Run python manage.py migrate immediately
-
Rename the app folder to lowercase
-
Restart the database server
Explanation:
Registering the app in INSTALLED_APPS lets Django know the app exists and should be included.
How does one enable URL routing for a newly created app in a Django project?
-
By editing the app’s models.py file
-
By creating a new template folder only
-
By adding the app folder to STATICFILES_DIRS
-
By adding include(...) for the app’s urls module in project’s urls.py
Explanation:
Including the app’s urls via include() in the project’s urls.py connects its URL patterns to the main project routing.
Quiz Completed Successfully
Your Score : 2/3
Accuracy : 0%
Login to View Explanation
1/3
1/3
< Previous
Next >
Explore
Python Fundamentals
Python Data Structures
Advanced Python
Data Science with Python
Web Development with Python
Python Practice