37

Background:

When I run the django-admin.py loaddata example.json I get this error. "ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined." I understand the problem. It needs the DJANGO_SETTINGS_MODULE to be able to access the database to do this import. I've had this problem before and I've managed to side step it thus far.

In reading the docs, I discovered that the manage.py is a wrapper for django-admin.py; it puts the project on the sys.path and sets the DJANGO_SETTINGS_MODULE environment. Woot! Whoa! I know how to fix my problem.

Soo... Why do the Django documentation code examples use django-admin.py instead of manage.py when demonstrating subcommands such as loaddata and dumpdata?

2 Answers 2

34

If your DJANGO_SETTINGS_MODULE environment variable is set, you can use django-admin.py from any working directory, whereas you need to be in the project directory to use ./manage.py (or have it in your path).

Use virtualenv, and have DJANGO_SETTINGS_MODULE set by bin/activate, and then you can use django-admin.py.

9

Why do the Django documentation code examples using django-admin.py instead of manage.py when demonstrating subcommands such as loaddata and dumpdata?

Well, because these scripts are the same in priciple, with the differences, you already mentioned. The Django docs also mention

django-admin.py <subcommand> [options]
manage.py <subcommand> [options]

side by side. Usually you use django-admin.py to start a new project or application and manage.py to do the rest.

1
  • 4
    I do think this makes the documentation more confusing for less experienced users and I've got about 9 months working with django. Thanks for your help! Jul 11, 2010 at 0:58

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.