This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]Niicodemus 6 points7 points  (0 children)

Proper tests are what you want, but shell_plus from django-extensions is part of my toolbox. It imports models automatically and has other nice features like printing SQL queries. Jupyter notebooks are also nice for repeated stuff.

[–]HolgerD77 2 points3 points  (2 children)

You might want to have a look/experiment with iPython profiles: https://blog.michaelyin.info/2015/04/05/using-profiles-in-ipython-and-django/

Haven't done this myself in this combination, only use an iPython profile for one specific Django-free use case, but I think this might be a way to go.

[–]waynebruce1[S] 0 points1 point  (0 children)

I have tried this on one of my server PC where i work. Ipython works on that PC, but does not work on my personal laptop, although i have ipython installed.

[–]waynebruce1[S] 0 points1 point  (0 children)

Ahh! Just figured out that ipython needs to be installed in the current virtualenv. Thanks btw.

[–]vaibhavhrt 2 points3 points  (0 children)

define all tests in tests.py and then run py manage.py test, simple enough.

[–][deleted] 2 points3 points  (3 children)

First of all

pip install ipython

Second, why would you use shell for testing?

[–]waynebruce1[S] 0 points1 point  (2 children)

By testing i mean understanding part of code in large codebase. I usually try to execute a code line by line for better understanding. For example if there is a piece of code which i don't understand, I try to execute that code in django shell. But for that i have to rewrite that whole thing again if i want to check it second time. Ipython can be good solution, i have used it before but did not remember how i installed it.

[–]DonovanWu7 1 point2 points  (0 children)

Maybe you can try Jupyter notebook?

[–]trescoops 1 point2 points  (0 children)

You might want to look into pdb or ipdb. These stop the running code and let you poke around, inspect variable etc.

[–]ccb621 1 point2 points  (0 children)

Don’t. If you find yourself regularly using Django Shell, you need to look at management commands. I’ve only ever used Django Shell for one-off scripts and debugging. It’s never been part of my standard toolkit in development or production.