[Django]-Running Django Custom Management Command – Path Issues

7👍

When you use Django, there are two important rules.

First.

You have a settings.py file which must be used by the web server and all the manage.py commands. All of them.

The default place to look for the settings.py file is the current working directory. You can change this with the PYTHONPATH and the DJANGO_SETTINGS_MODULE environment variable.

The manage.py is created for you in the same directory as the settings.py.

You can use django-admin.py --settings=some.module if you don’t want to use manage.py.

Second.

The manage.py commands do not have any “path” to them. They’re all just one-word commands, no matter where they happen to live in your application tree.

You never do this: python schoolcommand/manage.py createcampaign unless (somehow) your settings.py is not in the same directory as your manage.py.

You normally do this:

cd /path/to/your/settings
python manage.py createcampaign

If your settings is in code/schoolcommand that means that your web site and all your commands will operate in that directory.

👤S.Lott

Leave a comment