Creating First Django App0%

Creating First Django App

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

Creating First Django App

In Django, features are organized into modular, decoupled applications. When you create an app, Django scaffolds a standardized directory structure containing models, views, tests, and admin configurations. Learning how to create, register, and wire an app into the URL routing pipeline is the primary workflow of Django development.


1. Scaffolding an App with startapp

To create a new app named articles:

Bash / Terminal
python manage.py startapp articles

Django generates the following files:

Output
articles/
├── __init__.py
├── admin.py # Registration of models with Django Admin dashboard
├── apps.py # App configuration metadata
├── migrations/ # Auto-generated database migration scripts
│ └── __init__.py
├── models.py # Data models and database schemas
├── tests.py # Unit and integration test suites
└── views.py # Request handling and HTTP response logic

2. Registering the App in INSTALLED_APPS

Django will not detect your app's models, migrations, or templates until it is registered in settings.py:

Python
# config/settings.py
 
INSTALLED_APPS = [
# Core apps...
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
 
# Custom Domain Apps
"articles.apps.ArticlesConfig", # Or simply 'articles'
]

3. Writing Your First View (views.py)

A Django view is a Python callable (function or class) that takes an HttpRequest object and returns an HttpResponse object.

Python
# articles/views.py
from django.http import HttpResponse, JsonResponse
 
def home_view(request):
return HttpResponse("<h1>Welcome to Enterprise Django Platform</h1>")
 
def health_check(request):
return JsonResponse({
"status": "healthy",
"service": "articles-api",
"version": "1.0.0"
})

4. App-Level URL Routing (articles/urls.py)

Create a dedicated urls.py inside the articles/ directory:

Python
# articles/urls.py
from django.urls import path
from . import views
 
# Application namespace for reverse URL resolution
app_name = "articles"
 
urlpatterns = [
path("", views.home_view, name="home"),
path("health/", views.health_check, name="health-check"),
]

5. Wiring App URLs to the Project Root

Connect the app's URLs to the root config/urls.py:

Python
# config/urls.py
from django.contrib import admin
from django.urls import path, include
 
urlpatterns = [
path("admin/", admin.site.urls),
path("articles/", include("articles.urls")),
]

Now visiting http://127.0.0.1:8000/articles/health/ returns the JSON payload:

JSON
{
"status": "healthy",
"service": "articles-api",
"version": "1.0.0"
}

Interactive Quiz

Practice Quiz

Question 1
What command scaffolds a new application module in a Django project?
Question 2
What happens if you forget to add a newly created app to INSTALLED_APPS in settings.py?
Question 3
What is the fundamental contract of a Django view function?
Question 4
What is the purpose of setting app_name = "articles" in an app's urls.py?
Question 5
In which file should you define database tables and entity schemas for an app?
Next Lesson

Creating Models

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Django Project StructureCreating Models

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext