问题
I'm having a weird issue with something in a deployed django app (long story). Something that might help me is to know:
How django goes about detecting and maintaining a list of active management commands?
回答1:
Some things you should consider if you have troubles executing a management command:
- The app containing the command has to be in
settings.INSTALLED_APPS. - To be recognized as an app the package has to contain a
models.py(although it can be empty). - All packages need to have an
__init__.pyfile (your app's directory as well as themanagementandcommandfolder). - Sometimes Django seems to be choking on something like an
ImportErrorthat doesn't get displayed properly - so it might help to open amanage.py shelland try something likeimport MyCommand from myapp.management.commands.mycommand.
回答2:
It looks for any module under management.commands inside installed applications. See https://docs.djangoproject.com/en/dev/howto/custom-management-commands/ for mor details.
来源:https://stackoverflow.com/questions/14318899/how-does-django-register-management-commands