English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Django Lifecycle


A project is the sum of many applications. Each application has an objective and can be reused in another project, such as a contact form on a website, which can be an application and can be reused in other applications. See it as a module of the project.

Create an application

We assume that the project folder is located. We have the main project 'myproject' folder, and there is a file: manage.py in the first-level folder, and execute the following command −

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
C:\myproject> python manage.py startapp myapp

The newly created 'myapp' application is similar to a project, and the application structure created by Django in the 'myapp' folder is as follows −

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
myapp/
    __init__.py
    admin.py
    models.py
    tests.py
    views.py

       __init__.py − Just to make sure python treats this folder as a package.            admin.py − This file helps you modify the application in the admin interface.            models.py    − This is the storage of all the application models.            tests.py − This is the unit test.            views.py    − This is the application view.    

Get the project to understand the application

At this stage, we have the application 'myapp', and now we need to register it to the Django project 'myproject'. To do this, add the application name (to the settings.py file) to update the INSTALLED_APPS tuple in your project. -

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myapp',
 )