Create a new app in a Django project
October 19, 2020 Β βΒ 1Β min read
To create a new app in Django we utilize the startapp
command. This creates a Django app directory with a specified app name.
The app is created in by going in the root folder of your Django project and run the following command. The root folder is where the manage.py file is by the way.
$ python manage.py startapp plebapp
This results in a new directory being created named plebapp
with the file structure as shown below.
$ tree plebapp
plebapp
βββ admin.py
βββ apps.py
βββ __init__.py
βββ migrations
βΒ Β βββ __init__.py
βββ models.py
βββ tests.py
βββ views.py
In order to use this app we are almost set. To actually include the app in our projects it has to be added to INSTALLED_APPS
in the settings. You can reference the new app by its name.
INSTALLED_APPS = [
...
'plebapp',
]
Or by referencing the Config class you find in ./plebapp/apps.py
.
INSTALLED_APPS = [
...
'plebapp.apps.PlebappConfig',
]