How to Create Django App

If you want to create a project using Django then you will also have to learn how to create a Django app that will help you to develop different tasks of your project quickly.

For your better understanding, I have explained Django applications with some examples. Once you learn it, you can easily any kind of apps for your website.

Before lerning it, you must learn these topic –

How Install Django on Windows & Ubuntu

How to create Django Project

Create and Install Django App

First of all, you will know about Django App and its folder structure and also, how to create & install it using command line.

Djnago App

Django app is defined for different parts or functionality of a web applications. It is always created inside the root directory folder of Django project.

Suppose that we have to develop a project in Django for the Institue named codingstatus that should be performed different tasks like sign up, log in, faculty, student, attendance, fees, exam, result & course. then you can create separate apps for those tasks.

Project Name – codingstatus

Apps Name –

  • sign up app
  • login app
  • faculty app
  • student app
  • attendance app
  • course app
  • fees app
  • exam app
  • result app

Create Djnago App

You can create a Django App by running this command in your terminal. But make sure that a Django & Django Project must be installed in your system

python manage.py startapp appName

Example –

python manage.py startapp signup

Install Django App

After creating app, you will have to install it by registering in settings.py file of inner project folder. otherwise, Djano will not consider it.

INSTALLED_APPS = [
    'appName1',
    'appName2',
    'appName3',
]

Example –

INSTALLED_APPS = [
    'signup',
]

Django App Directory Structure

If you create a Django app named signup inside the root directory of codingstatus project. The you will get the following directory structure –

myproject
  |__myproject
  |__ signup
  |     |__ migrations/
  |     |      |__ __init__.py
  |     |__ __init__.py
  |     |__ admin.py
  |     |__ apps.py
  |     |__ models.py
  |     |__ tests.py
  |     |__ views.py
  |__ manage.py

Here, we will discuss only the folder structure of created app named signup one by one in details –

migrations

By default, This folder is considered a python package due to containing the _init.py file.

Also, all the migration files will be created in this folder while you run the makemigration command

admin.py

In this file, You will have to register models that contains information about database tables & their fields.

apps.py

You can use this file to configure the app

models.py

In this file, You can create a model for your app.

A model contains the information of database tables and their fields & attributes

tests.py

In this file, you can write code to test working of the app

views.py

In this file, We will write code to create views that will display on the front-end.

Note – Here, I have provided you a basic information of the app, you will understand the usage of these files completely when you work on a project.

Steps to Create Django App

Here, I will create Django App using command line terminal on the windows. If you have linux & mac then you can also use the given command line & these steps.

But you have to use starting default command according to your operating system. for example – if you are using linex then you will have to use sudo before provide command by me

Now, You can follow these steps to create a Django App inside a root directory quickly

1. Open Command line Terminal

First of all, you have to open command line terminal and go into your project folder.

Here , I have created a project folder named djangoproject in D drive of my systm. So, I have opened command with these path

D:\> djangoproject

2. Create a Django Project

then run this command to create Django project with the name of codingstatus

D:\> djangoproject>django-admin startproject codingstatus

3. Go to Root Project Directory

Now, you have to into root directory of the created Django project by running this command –

D:\> djangoproject>cd codingstatus

then you will move to project folder codingstatus

D:\> djangoproject>codingstatus>

4. Run manage.py startup appName

After that, run command manage.py startup appName. But You have to put your own app name in place of appName.

Suppose you have to create multiple app like signup, login, faculty, student, attendence, course, fees, exam, & result. But you have to run command one by one for each app.

D:\> djangoproject>codingstatus>python manage.py startapp signup
D:\> djangoproject>codingstatus>python manage.py startapp login
D:\> djangoproject>codingstatus>python manage.py startapp faculty
D:\> djangoproject>codingstatus>python manage.py startapp student
D:\> djangoproject>codingstatus>python manage.py startapp attendence
D:\> djangoproject>codingstatus>python manage.py startapp course
D:\> djangoproject>codingstatus>python manage.py startapp fees
D:\> djangoproject>codingstatus>python manage.py startapp exam
D:\> djangoproject>codingstatus>python manage.py startapp result


After running the above commands, you will get the created app folders in the root directory of codingstatus.

5. Register Django App in Settings.py

At last, resgister all the created apps within INSTALLED_APPS=[ ] array in settings.py file of inner project folder of codinstatus –

INSTALLED_APPS = [
    'signup',
    'login',
    'faculty',
    'student',
    'attendence',
    'course',
    'fees',
    'exam',
    'result'
]

What’s Naxt –

You will learn to create function based view in Django that will be posted as soon as possible.