English 中文(简体)
• 如何以q光方式开始支离机。
原标题: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()

就如何改变这一法典以开始采用qtconsole模式提出建议?

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)

现在可以进口我的模型,列出所有事例等等。

最佳回答

我制作了一幅带有以下文字的剪辑:

/path/to/ipython
qtconsole --pylab inline -c "run /path/to/my/site/shell.py"

如果你想要冷却的线垫字图,则只需要<条码>-pylab>部分。

我在<代码>/path/to/my/site上创建了一个字典<>。 注

import os
working_dir = os.path.dirname(__file__)
os.chdir(working_dir)
import settings
import django.core.management
django.core.management.setup_environ(settings)

我的手脚带给我一个ip子,使我受益。

问题回答

docs here 说:

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).

因此,应当确定这种环境变量,然后运行ipython qtconsole。 你们可以作一个简单的文字,自动为你们做。

自Django第1.4版以来,对<代码>django. 核心. management.setup_environ()的使用作了解释。 用于IPython笔记和QTconsole的解决方案就是这一解决办法。

In [1]: from django.conf imp或t settings

In [2]: from mydjangoproject.settings imp或t DATABASES as MYDATABASES

In [3]: settings.configure(DATABASES=MYDATABASES)

<>Update: 如果你与Django 1.7合作,你还需要执行以下任务:

In [4]: imp或t django; django.setup()

利用django.conf.gings.configure(),你具体说明了贵国项目的数据库环境,然后你可以以惯常的方式查阅所有模型。

如果你想要使这些进口自动化,你可以这样作:

ipython profile create mydjangoproject

每个简介都有一份称为<代码>的名录<>启动。 你们可以在那里放置任意的甲 Python,在IPython开始之后,他们就会被处决。 就此而言,你发现它属于这种情况。

~/.ipython/profile_<mydjangoproject>/startup/

此处仅作文字说明,其中载列上述代码,可能附在try。 处理<代码>Imp或tErr或的条款。 之后,你可以以这样的姿态开始IPython:

ipython qtconsole --profile=mydjangoproject

ipython notebook --profile=mydjangoproject

I also wanted to open the Django shell in qtconsole. Looking inside manage.py solve the problem for me: Launch IPython qtconsole, cd to the project base directory and run:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

Dontabe将我的项目改为你的项目名称。

你们可以建立一支延伸基地的军舰,并进口IPythonQtConsoleApp。

1. 在你的申请/管理/公摊中,编造“qtshell.py”:

from django.core.management.commands import shell

class Command(shell.Command):
    def _ipython(self):
        """Start IPython Qt console"""
        from IPython.qt.console.qtconsoleapp import IPythonQtConsoleApp
        app = IPythonQtConsoleApp.instance()
        app.initialize(argv=[])
        app.start()

然后,仅管理<代码>python。 py qtshell

<代码>shell_plus的一个无证特征是,能够以“只温和”的方式操作。 这使得我们能够从另一个壳体,例如一个 running子连接起来。

例如,在一例中:

django-admin shell_plus --kernel
# or == ./manage.py shell_plus --kernel

这将印刷如下内容:

# Shell Plus imports ...
...

To connect another client to this kernel, use:
   --existing kernel-23600.json

然后,在另一辆车上:

ipython qtconsole --existing kernel-23600.json

现在,这应该打开一个QtConsole。 另一端是,你不能再驾车,而是可以打到Ctrl+Z,并运行bg,以说明目前进行的背景工作。

您可安装rel=“nofollow”>django分机。 之后

python manage.py shell_plus --ipython




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签