The difference between a project and an application in Django and how to create an application

In Django,

Project : regarded as the result of Django installation based on certain settings;
application : expressed as a combination of model, view, template, and URL;

The application interacts with the framework, provides specific functions, and can be reused in different projects. We can think of a project as a site that contains multiple applications, such as blogs, wikis, or forums, and can be reused by other projects.

Create an application

In the root directory of the project, you can run the following commands:

python manage.py startapp blog

This will generate the basic structure of the application as follows:

Insert picture description here

The detailed explanation of the above documents is as follows:

  • admin.py: You can register the model in this file and include it in the Django management site-using Django to manage the site is optional.
  • apps.py: This file contains the main configuration content of the blog application.
  • Migrations directory: This directory contains application data migrations. Migration allows Django to track changes in the module and synchronize the database accordingly.
  • models.py: All Django applications need to set up this file, which contains the data model of the application; but this file can also be left blank.
  • tests.py: You can add application tests to this file.
  • views.py: This file contains the logic content of the application. Each view receives an HTTP request and returns a response result after processing.

The above is some summary made by myself, which is very suitable for beginners.

Guess you like

Origin blog.csdn.net/Erudite_x/article/details/112338945