How does django register management commands

谁都会走 提交于 2019-12-24 07:35:36

问题


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:

  1. The app containing the command has to be in settings.INSTALLED_APPS.
  2. To be recognized as an app the package has to contain a models.py (although it can be empty).
  3. All packages need to have an __init__.py file (your app's directory as well as the management and command folder).
  4. Sometimes Django seems to be choking on something like an ImportError that doesn't get displayed properly - so it might help to open a manage.py shell and try something like import 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

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