When creating an app with python manage.py startapp myapp
, it automatically creates an apps.py
file.
from django.apps import AppConfig
class MyappConfig(AppConfig):
name = 'myapp'
When I removed it, everything seems to work as before (at least my tests all passed). Is it a bad practice to remove these kind of files from the apps? Should we keep them to avoid side effects?
Purpose of apps.py file: This file is created to help the user include any application configuration for the app. Using this, you can configure some of the attributes of the application. From Application Configuration documentation: Application configuration objects store metadata for an application.
A Django project is simply a web application consisting of one or more apps within it.
A project represents the entire website whereas, an app is basically a submodule of the project. A single project can contain multiple apps whereas, an app can also be used in different projects. A project is like a blueprint of the entire web application whereas, apps are the building blocks of an web application.
The recommended approach in Django is to use the app config in your INSTALLED_APPS
:
INSTALLED_APPS = [
'myapp.apps.MyappConfig',
...
]
If you do this, then the apps.py
file is required.
However, if you do not customize the app config at all, then it is possible to remove the apps.py
if you use the app name in INSTALLED_APPS
instead:
INSTALLED_APPS = [
'myapp',
...
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With