Shell of Python and Django

1

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

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 of invoking the Python interpreter?

    
asked by anonymous 25.05.2017 / 16:30

2 answers

4

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

You can do this environment setting manually by opening the shell with python , importing the Django package, and then setting the environment variable DJANGO_SETTINGS_MODULE to the settings.py of your project.

Using python manage.py shell is just one way that Django offers to make this setting easier for your project environment in the Python shell.

    
25.05.2017 / 16:49
1

When you open the "pure" python shell you have only the available packages available in your env. When opening via manage.py, you have available in the shell all the configuration and objects of your project, for example, you can import a class of any model from any app defined in the project, do CRUD (through those classes / models) , run manager commands, run test routines, and so on .... :-)

    
25.05.2017 / 16:48