Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct configuration for %autoreload in a Django ipython shell?

Ipython has a plugin called autoreload that will presumably reload all your modules after every command, so you can change the source and not have to quit the shell and reenter all your commands. See http://dsnra.jpl.nasa.gov/software/Python/tips-ipython.html for example.

However, this seems flaky at best when using it with Django, e.g. python manage.py shell gives me an IPython shell with Django context, but the autoreloading does NOT seem to work reliably at all.

Here's what I have added to my ipy_user_conf.py file:

def main():
    ... # rest of the fn here
    import ipy_autoreload
    ip.magic('%autoreload 2')

The autoreloading works in limited cases, maybe 10-20% of the time. Has anyone successfully configured this to work with Django?

like image 775
vaughnkoch Avatar asked Jun 04 '10 02:06

vaughnkoch


1 Answers

This answer might also be applicable to your situation. Django keeps its own cache of all models, so if you want to reload everything, you have to clean this cache manually.

like image 176
schot Avatar answered Oct 22 '22 05:10

schot