django project and app

project: project

app(application): application, application

The difference between them is that one is configuration and the other is code:

A project contains many Django apps and their configuration.

Technically, the role of a project is to provide configuration files, such as where to define database connection information, a list of installed apps, TEMPLATE_DIRS (template_dirs), and so on.

An app is a collection of Django features, usually including models and views, that exist in Python's package structure.

For example, Django itself has built-in apps such as a commenting system and an automated admin interface. It is worth noting that these apps are easy to port to other projects and reused by multiple projects.

If you're just building a simple web site, you probably only need an app. If it is a complex web site like Taobao and other e-commerce, you may need to divide these functions into different apps for later reuse.

Indeed, you can also do not need to create an app, such as the view written before, just simply put it in views.py, no app is required.

Of course, the system has a convention for apps: if you use Django's database layer (models), you must create a django app. The model must exist in this app. So, in order to start building our model, we have to create a new app.

Go to the mysite project directory and execute the following command to create a new app called books:

python manage.py startapp books

1

This command line code doesn't print anything when run, but it creates a books folder in the mysite directory. The contents of this folder are as follows:

books/

    __init__.py

    models.py

    views.py

2

These files contain the models and views for the app.

Take a look at the models.py and views.py files. They are all empty except for an import in models.py.

 

In fact, it can be abstractly understood that a project is the final completed project (such as a puzzle), and an app is a piece of the puzzle. Multiple apps form a large project (such as a puzzle split into 1,000 pieces), and a single app forms a small Projects (like a 9-piece children's puzzle), and reusing apps in different projects is the same function call (for example, two different frames of motorcycles and cars are equipped with the same parts that act as engines), and a single app is completed. The simple content is like the content of the pos machine on the web page currently linked to by this dish.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326925149&siteId=291194637