问题
I've created a package for use with django, the main feature of which is accessible through a management command. However, in order to make management commands accessible, django seems to insist on the package being listed as an app in INSTALLED_APPS
in settings.py
.
This application is merely used as part of our build process while doing intergration testing. It does not even need to be installed on developer machines, let alone end up in our production environment. However, since it needs to be in settings.py
's installed apps, it also spreads to requirements.txt
, as it suddenly breaks builds wherever it is not installed.
Is there a way to inject a management command without the package being installed as a full-blown app?
Alternatively: is there a standard/recommended way to make a command available to tox
in a different way than through a management command?
回答1:
One solution is to have a separate settings.py for the build process that adds the app containing this command to INSTALLED_APPS. Then you can run manage.py mycommand --settings=build_settings
or whatever.
The settings file itself can be as simple as:
from main_settings import *
INSTALLED_APPS += ['myapp']
来源:https://stackoverflow.com/questions/40333400/django-add-management-command-without-installing-as-app