Django的一个重要特性是你可以打开一个python解释器设置,用于你的项目。这可用于分析数据库中的对象,并允许在项目上执行任何python命令。我发现Django开发很重要。使用以下命令在项目目录中调用它:
$ python manage.py shell
我刚刚开始开发一个新项目,由于某种原因,shell无法正常工作。我已经在线查看错误,但没有找到任何内容。我非常感谢有关此错误的任何帮助:
Traceback (most recent call last):
File "manage.py", line 11, in
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 362, in execute_manager
utility.execute()
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 222, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Library/Python/2.6/site-packages/django/core/management/commands/shell.py", line 29, in handle_noargs
shell = IPython.Shell.IPShell(argv=[])
AttributeError: 'module' object has no attribute 'Shell'
提前感谢您的帮助!
答案 0 :(得分:12)
似乎IPython以某种方式错误地安装。尝试使用以下命令启动shell:
./manage.py shell --plain
启动标准的Python shell,而不是IPython。如果可行,则尝试完全删除IPython并重新安装。
答案 1 :(得分:6)
IPython 0.11有一个不同的API,在最后的Django版本中存在修复。
对于较旧的Django版本,您可以使用IPython 0.10,它可以正常工作:
pip install ipython==0.10