Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to use django shell without restarting when change code

I use Django shell_plus for testing my models and views

But when i get error then i change the code and then i have to restart my shell_plus

and then type all commands which i have typed

Is there any way that i don't need to restart shell and i can chnage the code and then test the command again

like image 238
user1958218 Avatar asked Jun 28 '13 03:06

user1958218


People also ask

What is Django shell plus?

shell_plus is Django shell with autoloading of the apps database models and subclasses of user-defined classes. The --notebook argument tells shell_plus to open in a Jupyter notebook.

What is the use of python manage PY shell command in Django project?

I'm going to start the Django shell by typing python manage.py —as so often—and then shell . This opens up a terminal. 00:30 However, it has the Django settings already imported, so it allows you to work directly from the root folder of a Django project.


1 Answers

I personally in such cases just record my session from shell_plus to file, and then call this file from within shell_plus after manually reloading. Both is possible with iPython, which is used by shell_plus by default. (If you don't have iPython installed, just pip install ipython and it should automatically work after that, I think).

The recorded script is also often nice to keep as part of the project, as it's basically a small integration test. With minor modifications it could be executed outside shell as a standalone script, which is convenient.

If you definitely want to use reloading, I think this answer might be able to help you:

  • How do you reload a Django model module using the interactive interpreter via “manage.py shell”?.
like image 156
Anton Strogonoff Avatar answered Sep 29 '22 21:09

Anton Strogonoff