Django add management command without installing as app

好久不见. 提交于 2019-12-12 15:26:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!