0

当我在python manage.py shell. 基本上我有一个小 shell 脚本可以让我进入>>>shell,但我希望能够在我的 views.py 脚本中自动推送导入调用,这样我就不必每次想要测试时都输入它们某物。我尝试将它们写在 shell 脚本中,但似乎它们没有传递给 python shell。

这是我到目前为止所拥有的。

#!/usr/local/bin/bash
python ~/path/to/manage.py shell

import datetime
from django.shortcuts import render_to_response
from mymodel.models import *
from myapp.forms import *
... and so on

我想要发生的是将所有导入行推送到 python shell 中,这样我就不必每次想在 shell 上调试时都键入/复制粘贴它们。

4

2 回答 2

2

将您的前传放入文件中。在这里,我假设它位于一个适当命名为prequel. 然后你可以像这样调整你的 bash 脚本:

cat prequel - | python ~/path/to/manage.py shell

cat连接文件,但它可以将标准输入视为文件,因此我们连接您的前传,然后连接标准输入,然后将该连接连接到 shell。

于 2013-02-23T02:53:17.177 回答
1

还有 django 扩展: http: //www.michelepasin.org/blog/2010/11/17/preloading-stuff-in-djangos-interactive-shell/

于 2013-02-23T02:54:25.033 回答