When you run python manage.py shell
alot of the same set up happens as what happens when you run runserver
. In particular, all of the ready
methods in your AppConfig
s will be called.
For this reason there is no need for your server to be running to do the testing you want.
You can even test this. Simply add a print("This happens")
and run python manage.py shell
. You should see something like this:
(env)your-current-location % python manage.py shell
This happens <---- Here you see it is printed
Python 3.8.6 (default, Oct 8 2020, 14:06:32)
[Clang 12.0.0 (clang-1200.0.32.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
For what it's worth, you can open a shell, and run your server at the same time yes. But these will be different processes, and variables set on classes, will refer to differnt things. They will be (at the code level) completely separate.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…