After setting up your Django project and understanding its structure, the next important step is to create your first Django app. In Django, a project is made up of one or more apps, and each app is responsible for a specific feature or section of the website.
In this tutorial, you will learn what a Django app is, why apps are important, how to create one, how to register it in your project, and how to begin using it to build real features.
A Django app is a self-contained module that handles one specific part of a website.
For example, if you are building a blog website, you might have:
Each app contains its own logic, such as:
This modular design is one of Django’s biggest strengths.
This is one of the most important beginner concepts in Django.
The project is the whole website or web application.
An app is one part of the website that performs a specific function.
Imagine you are creating an online learning platform:
This structure keeps the project organized and easier to manage.
Django encourages app-based development because it offers many advantages:
Instead of putting all code in one place, Django separates features into apps.
This makes large projects much easier to understand.
You create a new app when your project needs a new functional module.
For example:
blog for articlesshop for productsusers for authentication-related featuresdashboard for admin-style pagescontact for contact formsIn small beginner projects, you may start with only one app. In larger projects, you may have several apps.
To create an app, open your terminal in the Django project root where manage.py is located, then run:
python manage.py startapp blogHere, blog is the name of the app.
After running this command, Django creates a new folder named blog.
The new app folder usually contains:
blog/
├── __init__.py
├── admin.py
├── apps.py
├── migrations/
├── models.py
├── tests.py
└── views.pyLet us understand each file.
__init__.pyThis file tells Python that the folder is a Python package. It is usually empty.
admin.pyThis file is used to register models in the Django admin panel.
apps.pyThis contains the app configuration.
Example:
from django.apps import AppConfig
class BlogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'blog'
migrations/This folder stores migration files that track database structure changes for this app.
models.pyThis file is used to define database models.
tests.pyThis file is used to write tests for the app.
views.pyThis file contains the views that handle requests and return responses.
Creating the app folder is not enough. You must also tell Django that this app is part of the project.
To do that, open:
config/settings.pyFind the INSTALLED_APPS list and add your app name:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
]Now Django recognizes the blog app as part of the project.
If you do not add the app to INSTALLED_APPS, Django will not fully use it.
For example:
So after creating an app, registering it is an essential step.
Now let us add a simple view inside blog/views.py.
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello, this is my first Django app!")This view is a Python function that receives a request and returns a response.
When called, it shows simple text in the browser.
It is a best practice to give each app its own urls.py file.
Inside the blog folder, create a new file named:
urls.pyThen write:
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'),
]This connects the empty path '' to the home view.
So if the app is included at /blog/, then visiting /blog/ will call views.home.
Now you need to connect the app’s URLs to the main project.
Open:
config/urls.pyUpdate it like this:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('blog/', include('blog.urls')),
]/admin/ goes to the admin panel/blog/ goes to the blog app URLsSo now if you visit:
you should see:
Hello, this is my first Django app!
At this point, the flow works like this:
/blog/config/urls.py sends the request to blog.urlsblog/urls.py matches the empty path ''views.homeThis is your first working Django app.
render()Returning plain text is useful for testing, but most websites display HTML pages.
Instead of HttpResponse, you will often use render().
Example in blog/views.py:
from django.shortcuts import render
def home(request):
return render(request, 'blog/home.html')This tells Django to render an HTML template.
Inside your app, create the following folder structure:
blog/
└── templates/
└── blog/
└── home.htmlThen inside home.html, write:
<!DOCTYPE html>
<html>
<head>
<title>My Blog App</title>
</head>
<body>
<h1>Welcome to my first Django app</h1>
<p>This page is rendered from a template.</p>
</body>
</html>Now when you visit /blog/, Django renders the HTML page instead of plain text.
You may wonder why the template is stored like this:
templates/blog/home.htmlinstead of simply:
templates/home.htmlThe reason is to avoid template name conflicts between apps.
For example:
blog/home.htmlshop/home.htmlusers/home.htmlThis keeps templates organized and prevents confusion.
If the app is not added to INSTALLED_APPS, parts of it may not work correctly.
urls.py in the appWithout app URLs, you cannot organize routes cleanly.
If you do not use include('blog.urls'), Django will not know about your app routes.
If the file path or template name is incorrect, Django may raise a template error.
Views go in views.py, models go in models.py, and admin registration goes in admin.py.
Your project may now look like this:
my_django_project/
│
├── manage.py
├── config/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── asgi.py
│ └── wsgi.py
│
└── blog/
├── __init__.py
├── admin.py
├── apps.py
├── migrations/
├── models.py
├── tests.py
├── views.py
├── urls.py
└── templates/
└── blog/
└── home.htmlThis is a clean starting point for building features.
Choose app names that clearly describe their purpose.
Good examples:
blogusersshopordersdashboardAvoid vague names like:
app1testappmyprojectpartA clear name makes the project more readable.
Think of your Django project as a shopping mall.
Each store has its own staff, products, and organization, but all stores belong to the same mall.
That is how Django apps work inside a project.
In this tutorial, you learned how to create your first Django app using python manage.py startapp, explored the files Django creates, registered the app in INSTALLED_APPS, created a simple view, added app URLs, connected them to the main project, and rendered your first HTML template.
This is a major step in Django learning because apps are the building blocks of Django projects.
python manage.py startapp appname.INSTALLED_APPS.views.py.urls.py.INSTALLED_APPS?urls.py inside an app?Creating your first Django app is one of the most exciting steps in learning Django because it is where your project starts becoming real. You are no longer only configuring the framework, you are now building actual features.