Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should you use django-admin.py versus manage.py?

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?

like image 662
citadelgrad Avatar asked Jul 10 '10 18:07

citadelgrad


People also ask

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.

Why do we use manage py in Django?

It is your tool for executing many Django-specific tasks -- starting a new app within a project, running the development server, running your tests... It is also an extension point where you can access custom commands you write yourself that are specific to your apps.

Is Django admin good for production?

Django's Admin is amazing. A built-in and fully functional interface that quickly gets in and allows data entry is priceless. Developers can focus on building additional functionality instead of creating dummy interfaces to interact with the database.

What is admin py used for?

The admin.py file is used to display your models in the Django admin panel. You can also customize your admin panel. Hope this helps you.


2 Answers

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.

like image 163
Matthew Schinckel Avatar answered Oct 22 '22 08:10

Matthew Schinckel


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.

like image 27
miku Avatar answered Oct 22 '22 09:10

miku