Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to start django shell with ipython in qtconsole mode?

When i start django shell by typing python manage.py shell the ipython shell is started. Is it possible to make Django start ipython in qtconsole mode? (i.e. make it run ipython qtconsole)

Arek

edit: so I'm trying what Andrew Wilkinson suggested in his answer - extending my django app with a command which is based on original django shell command. As far as I understand code which starts ipython in original version is this:

from django.core.management.base import NoArgsCommand

class Command(NoArgsCommand):
    requires_model_validation = False

    def handle_noargs(self, **options):
        from IPython.frontend.terminal.embed import TerminalInteractiveShell
        shell = TerminalInteractiveShell()
        shell.mainloop()

any advice how to change this code to start ipython in qtconsole mode?

second edit: what i found and works so far is - start 'ipython qtconsole' from the location where settings.py of my project is (or set the sys.path if starting from different location), and then execute this:

import settings
import django.core.management
django.core.management.setup_environ(settings)

and now can i import my models, list all instances etc.

like image 806
agend Avatar asked Nov 23 '11 12:11

agend


1 Answers

The docs here say:

If you'd rather not use manage.py, no problem. Just set the DJANGO_SETTINGS_MODULE environment variable to mysite.settings and run python from the same directory manage.py is in (or ensure that directory is on the Python path, so that import mysite works).

So it should be enough to set that environment variable and then run ipython qtconsole. You could make a simple script to do this for you automatically.

like image 181
Thomas K Avatar answered Oct 03 '22 05:10

Thomas K