Django App vs Project

Django App vs Project

Everything in Django is centered around the idea of apps. Apps in Django are the self-contained directories that hold files that all work together to provide specific functionality for your Project. A Django project may consist of a single app, or many apps to provide its service. In fact, there is a site dedicated to providing developers all kinds of reusable apps, tools, and more for your Django projects. That site can be found at In this tutorial, we are going to keep building our Django project and add an app from scratch for a blogging functionality.

Adding An App

We can add a new app to our top-level project folder using the python startapp command. This app is going to be for managing posts in a blog system, so we are going to just call it posts.

djangoblog $python startapp posts

After running the command, it should create a new app inside of the Django project like so.

django managepy startapp

Register The App

Anytime you add an app to your Django project, it must be registered in the file like so.


Files Django Project and Apps

The table here displays all of the files and folders included in the root app created in the Django project vs the files and folders that are created with the startapp command.

Root App of Django Project App created with startapp command migrations

Modularizing URLs

Creating a new app did not create a new file for us. One convention is to add a file to any application folders so that you can have routes associated with that app inside its own directory. So we’ll go ahead and add a file to our posts app now.

django urlspy in apps

Now in the file, we want to follow the same flow that we have already learned. In our case, when the user visits the app home page, we want to display a list of posts. This will get us started.


from django.urls import path
from . import views

urlpatterns = [
    path('', views.post_list)

Now we need to add the post_list() function in the file.


from django.shortcuts import render

def post_list(request):
    return render(request, 'posts/post_list.html')

Namespacing Templates

The function above is trying to render a post_list.html template file that lives in the posts directory. We have not yet created this in the posts app, but we can do that now.

django namespace templates for apps

This is where we come into the namespacing convention when adding a templates folder to an app in Django. By convention, when you add a templates folder to an app, you will then put another folder inside of that which matches the app name. In our case, we have a posts app, so inside of templates, is another folder of posts. That means we can place the post_list.html template file in this folder. Namespacing is needed so that if various apps in the Django project have any template files with the same name, Django will know which template to render.

django template namespace

We can put some simple Html markup to get us started.


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
<h1>Posts List</h1>

Including URLs

In order for urlpatterns that are defined inside of a Django application to have any effect, they need to be included in the main file of the Django project root. You may recall from a prior tutorial that we already have a few urlpatterns defined in the djangoblog/ file. To activate the urlpatterns in posts/ we can add the following highlighted lines to the base file.

from django.contrib import admin
from django.urls import path, include
from . import views

urlpatterns = [
    path('', views.home),
    path('posts/', include('posts.urls')),
    path('about/', views.about)

What the code above does for us is the following. If a user visits the Django app with a browser and includes /posts in the URL, then Django says ok, use the file that exists in the posts folder for this.

Now we can try visiting to see this in action. Our new template file in the posts app is being displayed perfectly!

django template from posts app

Other Resources

Django App vs Project Summary

There are two very common commands you’ll use when working with Django.

  • startproject
  • python startapp

The first command is to get your Django project started. Once the main project is created, you can use the python startapp command to add apps to the Django project. A Django project can include many apps, each serving a specific purpose. In this tutorial, we added a posts app that is going to be the application to publish blog posts as we continue with Django. Up next, Models in Django.