Python Shell and Django

Asked

Viewed 1,210 times

3

I know that to open the interactive Python shell, we simply run on the operating system terminal:

python

But with Django installed, you can also open the shell using the command:

python manage.py shell

Is there any difference between the two ways to invoke the Python interpreter?

  • As far as I know, the Django shell is just a Python shell ready to interact with your Django environment. I believe this documentation can help: https://docs.djangoproject.com/en/1.11/ref/django-admin/#shell

2 answers

6


When opening the shell using python manage.py shell, inside the directory of your Django project, the environment will be configured so that it is possible to interact with the objects of your source code from the Python shell.

It is possible to do this environment setting manually by opening the shell with python, import the Django package and then configure the environment variable DJANGO_SETTINGS_MODULE to the settings.py of your project.

Use python manage.py shell is only one way that Django offers to facilitate this environment configuration of your project in the Python shell.

1

When Voce opens the python shell "pure" Voce has available only the packages available in its env. When opening via Manage.py, Voce has available, in the shell, all the configuration and objects of your project, and can, for example, import a class of any model from any app defined in the project, make CRUD (through these classes/models), execute manager commands, run test routines, and so on.... :-)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.