What is Django app + Creating an app

By Guru - May 12, 2021



What is Django app




What is a Django App?

There are two terms project and app in Django. A project refers to the entire application and all its parts and an app refers to a submodule of a project. it's self-sufficient and independent of all others app in the project. Each app in project have it own model.py. You might think it as a standalone python module. A simple project might only have one app. 

For example : The project is the whole website. You might structure it so there is an app for articles, an app for ranking tables, and an app for fixtures and results. If they need to interact with each other, they do it through well-documented public classes and accessor methods.

Creating app

Now it is time to create an app and understand the working and structure of an app.

If you already created virtual environment and project, enter the command below, if not create virtual enviroment and project.

To create app :
django-admin startapp myapp
Explanation :
  • django-admin : command to call django
  • startapp : command to tell django to start a new app
  • app_name  : app name of your choice, in case its myapp


I Will here explain only directory and files inside the myapp.

Explanation : 
  • myapp : It's your app main directory.
  • migrations : Migration is a way of applying changes that we have made to a model, into the database schema.
  • __init__.py : An empty file that tells Python that this directory should be considered a Python package.
  • admin.py :  It's a file which register models to the django-admin.
  • app.py : This file is created to help the user include any application configuration for the app.
  • models.py : A model is a class that represents table or collection in our DB, and where every attribute of the class is a field of the table or collection.
  • test.py : It is file used for testing process.
  • views.py : This file is the most important file of the Django app. A view is user interface when you render a website. A view function is python function that takes web request and return a Web response.
Our app is created but to use in project we need to specify it in project settings.py.

myproject(base dir) > myproject(root dir) > settings.py

 In settings.py add these lines in INSTALLED_APP
'myapp',


Wrap up
commands used :
django-admin startapp myapp

  • Share:

You Might Also Like

0 Comments