16👍
I love iPython but don’t like installing it in all my virtualenvs, and I’ve found a good solution to allow for that. Instead of using python manage.py shell
, you can just use the system iPython directly.
In order for this to work properly, you need to set the DJANGO_SETTINGS_MODULE so that it corresponds to your project.
export DJANGO_SETTINGS_MODULE=yourproject.settings
If this is your only Django project, the easiest solution is to add that line to your .bashrc
.
If you have several Django projects and want to avoid having to change the variable every time you switch between projects, you can add that export line above tailored to each project to the postactivate scripts of all your Django virtualenvs. For me, the postactivate script is at ~/.virtualenvs/myvenv/bin/postactivate
.
- [Django]-PHP Frameworks (CodeIgniter, Yii, CakePHP) vs. Django
- [Django]-Name '_' is not defined
- [Django]-Cannot access django app through ip address while accessing it through localhost
2👍
In my case, I really want to run IPython in multiple virtual environments (created using the default –no-site-packages) each used for a different Django project. I did not want to install IPython in each env.
As @Arash mentioned, exporting the DJANGO_SETTINGS_MODULE
works but it’s difficult to manage it when you have multiple projects.
I finally solved this issue in two parts.
First I added the directories “/usr/lib/python2.7/dist-packages” and “/usr/lib/pymodules/python2.7″to sys.path in the /usr/bin/ipython script as mentioned here.
Next, I use a manage_to_ipython.py
script to create a django-project-specific script called runipython.py
leveraging the manage.py
file created by django-admin.py
Once in each Django project, $cd <project_dir>
then run python manage_to_ipython.py
Now, to run IPython simply type ./runipython.py
The modified /usr/bin/ipython and the manage_to_ipython.py scripts can be found here.
- [Django]-Using django-admin on windows powershell
- [Django]-Django: For Loop to Iterate Form Fields
- [Django]-How to pass django rest framework response to html?