Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write custom django manage.py commands in multiple apps

Imagine I have two or more apps in my django project, I was able to successfully write and execute custom manage.py commands when I had only one app, A.

Now I have a new app, B, and as mentioned in https://docs.djangoproject.com/en/dev/howto/custom-management-commands/ I created directory structure of B/manangement/commands and wrote a custom module.

When I run python manage.py , it keeps complaining Unknown command. However if I move this command to other app, i.e. to folder A/management/commands and then run python manage.py <command>, it works seamlessly.

Any idea how I can resolve this?

like image 587
user1335608 Avatar asked Jul 31 '13 05:07

user1335608


People also ask

What is Django-admin and manage py and app creation and explain its commands?

django-admin is Django's command-line utility for administrative tasks. This document outlines all it can do. In addition, manage.py is automatically created in each Django project.

What is the difference between Django-admin and manage py?

Django-admin.py: It is a Django's command line utility for administrative tasks. Manage.py: It is an automatically created file in each Django project. It is a thin wrapper around the Django-admin.py.


2 Answers

As @Babu said in the comments, It looks like you may not have added your app to INSTALLED_APPS in your settings.py.

It's also possible that you're missing the __init__.py files (that are required in python modules) from the management and commands folders.

Alternatively, (sorry to say this) you may have misspelt "management" or "commands", or even the name of the command you're running.

like image 63
meshy Avatar answered Oct 03 '22 15:10

meshy


Most likely, you did not include app B in your settings.py

If you just run python manage.py with no command specified, it will print the list of commands Django can find.

This can help rule out misspelling the command name, but doesn't answer the question of whether or not you made management and commands both packages, or if app B simply isn't listed in your settings.INSTALLED_APPS

like image 26
NickCSE Avatar answered Oct 03 '22 14:10

NickCSE