Sitemap
Lavu Sravya

Lavu Sravya

Django - Create App

2 min readFeb 13, 2023

Before you dive in to this article, I recommend you to go through this

A Django project is a collection of configurations and apps. One project can be composed of multiple apps or a single app. Django’s ability to create multiple applications within a single project is vital for scalability.

A Django application is a small component that’s dedicated to a specific section of project. To create an app, go to the directory of manage.py file

(myenv) C:\Users\YourName\ProjectName>django-admin startapp AppName

After executing the above command, we get following directory structure:

As we have already discussed the project files structure in previous article. We can focus on app files structure here:

  • __init__.py: This is a python file used in almost all python applications which allow app packages to be imported from other directories.
  • migrations/: Here Django store some files to keep track of the changes you create in the models.py file and synchronize them with database.
  • admin.py: This is a configuration file for Django Admin (A built-in Django command-line utility for administrative tasks)
  • apps.py: This is a configuration file of the application itself.
  • models.py: Here is where we define the entities of our Web application. The models are translated automatically by Django into database tables.
  • tests.py: This file is used to write unit tests for the app.
  • views.py: This handles the request/response cycle of Web application.

Now that we created our first app, let’s configure our project to use it. To do that, open the settings.py file and try to find the INSTALLED_APPS variable and then just add your app name to the list like this

Get Lavu Sravya’s stories in your inbox

Join Medium for free to get updates from this writer.

INSTALLED_APPS = [ ‘django.contrib.admin’, ‘django.contrib.auth’, ‘django.contrib.contenttypes’, ‘django.contrib.sessions’, ‘django.contrib.messages’, ‘django.contrib.staticfiles’, ‘AppName’ ]

We all know how an admin interface is important for a web project. Django provides a ready-to-use user interface for administrative activities which automatically generates admin interface based on your project models.

We have to initiate database and create a superuser to perform CRUD operations on models through admin UI (http://127.0.0.1:8000/admin)

(myenv) C:\Users\YourName\ProjectName>python manage.py migrate

(myenv) C:\Users\YourName\ProjectName>python manage.py createsuperuser

Now that you have a basic outline of how to create an app and configure it to a project. You can get started with Django and create multiple apps.

--

--