Majid199372
Majid199372

Reputation: 21

python -m django startproject vs django-admin startproject

hi everyone what is difference between python -m django startproject and

django-admin startproject

if it have any different so which one is better for use ?

Upvotes: 0

Views: 170

Answers (1)

EDG956
EDG956

Reputation: 982

TL;DR

They are about the same, with manage.py doing the same as django-admin, but setting the DJANGO_SETTINGS_MODULE environment variable beforehand.

Answer

django-admin is a script installed by setuptools when installing django (i.e: pip install django). The script generated executes something similar to (but not exactly):

from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)

You can see its definition in setup.cfg:48, where there's an entrypoint defined to run the function django.core.management:execute_from_command_line.

Similarly, manage.py looks something like:

...imports

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

So, as the docs say: manage.py is automatically generated and does the same as django-admin, but it sets the module DJANGO_SETTINGS_MODULE environment variable.

Upvotes: 1

Related Questions