apps.py,django项目中的appconfig有什么用。如何以及为什么使用它?有人可以用简单的方式解释一下吗
What is the use of apps.py, appconfig in django project. How and why to use it? could someone explain in a simple way
from django.apps import AppConfig
class App1Config(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app1'
Django 已经提供了最好的解释documentation。
To configure an application, create an apps.py module inside the
application, then define a subclass of AppConfig there.
When INSTALLED_APPS contains the dotted path to an application module,
by default, if Django finds exactly one AppConfig subclass in the
apps.py submodule, it uses that configuration for the application.
This behavior may be disabled by setting AppConfig.default to False.
If the apps.py module contains more than one AppConfig subclass,
Django will look for a single one where AppConfig.default is True.
If no AppConfig subclass is found, the base AppConfig class will be
used.
from django.apps import AppConfig
class App1Config(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app1'
Django 已经提供了最好的解释documentation。
To configure an application, create an apps.py module inside the application, then define a subclass of AppConfig there.
When INSTALLED_APPS contains the dotted path to an application module, by default, if Django finds exactly one AppConfig subclass in the apps.py submodule, it uses that configuration for the application. This behavior may be disabled by setting AppConfig.default to False.
If the apps.py module contains more than one AppConfig subclass, Django will look for a single one where AppConfig.default is True.
If no AppConfig subclass is found, the base AppConfig class will be used.