Django Creating an App


Build a Django App

In Django, a project is the full web system, while an app is a component or feature—like a blog, shop, or messaging module. Let’s go step-by-step to build one.


Use the Command Line

Inside your main project folder, run:

python manage.py startapp gallery

This generates a new folder called gallery, filled with starter files used to handle data, views, and more.


Explore the App Folder

Your new directory will look like this:

gallery/ 
├── admin.py 
├── apps.py 
├── models.py 
├── views.py 
├── tests.py 
├── __init__.py 
├── migrations/

Each file has a different role:

  • admin.py – Links models to Django's admin dashboard.
  • apps.py – App config info lives here.
  • models.py – Design your database tables here.
  • views.py – Handle logic that responds to browser activity.
  • tests.py – Put automated checks for your code here.
  • migrations/ – Tracks updates to your database structure.

Register the App

Now connect the new module to the main system.

Open your settings.py in the project folder, find the INSTALLED_APPS list, and add the app name:

INSTALLED_APPS = [    
        ...,    
       'gallery', 
] 

This enables Django to register your new component as part of the overall project architecture.


Make Models and Apply Changes

Suppose you declare a structure inside models.py such as:

from django.db import models  

class Photo(models.Model):     
         title = models.CharField(max_length=100)     
         Image = models.ImageField(upload_to='photos/')

To apply it to the database:

python manage.py makemigrations 
Python manage.py migrate

This creates and applies the database structure needed for your model.


Add Views and Routes

You can create your first logic inside views.py:

from django.http import HttpResponse  

def homepage(request):     
        Return HttpResponse("Welcome to the photo gallery!")

Then connect it to a URL.

Inside a new file urls.py in your app folder:

from django.urls import path 
from . import views  

urlpatterns = [     
      path('', views.homepage), 
]

And finally include this in the main urls.py:

from django.urls import include, path  

urlpatterns = [     
      path('', include('gallery.urls')), 
]

Now your app is live, connected, and ready for more development!


Prefer Learning by Watching?

Watch these YouTube tutorials to understand HTML Tutorial visually:

What You'll Learn:
  • 📌 Create Python Django apps with GitHub Copilot
  • 📌 #3 Django tutorials | First App in Django - part 1
Previous Next