Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

django
python
communitycreator

How to create an app in Django

Onyejiaku Theophilus Chidalu

Overview

A Django project can contain multiple apps. These apps don’t represent the entire application. Rather, they are small functional areas of our Django project.

For example, imagine you want to build a website like Edpresso. Edpresso is a very big website that has many different functions. Instead of implementing all these functions inside a Django project, we divide this project into small functional areas that are focused on one concern. We can create functional areas like drafts, submitted shots, published shots, etc. All of these functions are completely different functional areas. The functions we have for managing the drafts are completely different from the functions we have for managing submitted shots.

So with this analogy, we divide the Django project into multiple Django apps, with each app focused on one functional area.
The beauty of these apps is that you can reuse them across different Django projects because each app is essentially a Python package.

Django project vs Django app

Django project Django app
The entire application and all its parts or simply the whole website. A small functional area of our Django project.
Contains all the necessary tools required for a website. Completely different functional areas for a Django project.
A single Django project contains multiple apps in it. Multiple Django apps are created in a single project.

How to create a Django project

To learn how to create a Django project, check out this shot: How to create a Django project.

Creating a Django app

Now that we have successfully created a Django project, let’s create three apps: shots, submitted and published.

Starting with the first app we want to create, shots, key in the following command on your terminal window.

python manage.py startapp shots

Explanation

Python has a utility program, manage.py, that manages each app of a Django project. In the above command, we ask it to create an app called shots.

Type the following command on a new terminal window to create an app called submitted.

python manage.py startapp submitted

Enter the command below on a new terminal window to create the app called published.

python manage.py startapp published

Note: When you create a name for a Django app using the manage.py utility, the name will also be used as the application directory name.

Output

Back in your Folders, locate the previous project created. There, you will find the apps you just created. Each of the apps should contain the following subfolders:

  • Migrations
  • __init__.py
  • admin.py
  • models.py
  • tests.py
  • views.py

These subfolders are what make up a typical Django app. If you find these subfolders inside the apps you just created, it means that your codes were successfully executed.

RELATED TAGS

django
python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring