I'm working with Django and I use the Django shell all the time. The annoying part is that while the Django server reloads with code changes, the shell doesn't, so every time I make a change to a method I'm testing, I need to exit the shell and restart it, re-import all the modules I need, reset all the variables I need, etc. While iPython history saves a lot of typing on this, this is still a pain. Is there a way to make the Django shell reload automatically, the same way the Django development server does?
I know about reload(), but I import a lot of models and generally use from app.models import * syntax, so reload() isn't much help.
I'd suggest using the IPython autoreload extension.
./manage.py shell In [1]: %load_ext autoreload In [2]: %autoreload 2And from now on, all imported modules will be updated before evaluating.
In [3]: from x import print_something In [4]: print_something() Out[4]: 'Something' # Do changes in print_something method in x.py file. In [5]: print_something() Out[5]: 'Something else' It also works if something was imported before the %load_ext autoreload command.
./manage.py shell In [1]: from x import print_something In [2]: print_something() Out[2]: 'Something' # Do changes in print_something method in x.py file. In [3]: %load_ext autoreload In [4]: %autoreload 2 In [5]: print_something() Out[5]: 'Something else'