使用 Django 1.5 和 IPython 获取 NameError [英] Getting NameError with Django 1.5 and IPython

查看:31
本文介绍了使用 Django 1.5 和 IPython 获取 NameError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 Django 1.5.1、Python 2.7.2 和 IPython 0.13.2.如果我从我的 Django 项目目录中执行python ./manage.py shell",我会收到以下错误:

I'm running Django 1.5.1, Python 2.7.2, and IPython 0.13.2. If I do "python ./manage.py shell" from within my Django project directory, I get the following error:

from django import forms
class CommentForm(forms.Form):
    name = forms.CharField()

NameError: name 'forms' is not defined.

我知道表单的定义是因为我在执行dir(forms)"时可以看到它.我注意到此错误仅在我在 REPL 中运行 iPython 时发生.如果我启动 REPL 并且只使用普通的旧 Python 解释器,则不会发生错误.

I know forms is defined as I can see it when it do "dir(forms)". I've noticed that this error only occurs when I'm running iPython within the REPL. If I start the REPL and only use the plain, old Python interpreter, the error doesn't occur.

有没有其他人遇到过这个问题?如果是这样,您是否知道它为什么会发生以及是否有解决方法?

Has anyone else experienced this problem? If so, do you know why it's occurring and whether or not there's a work-around?

我应该补充一点,我在过去在 REPL 中创建类时遇到了问题,直到我在类中创建了一个元类并定义了一个app_label"变量.在这种情况下,这并没有什么不同.

I should add that I've had problems in the past creating classes in the REPL until I created a meta class within the class and defined an "app_label" variable. That didn't make a difference in this situation.

谢谢.

推荐答案

django 1.5 无法正确启动 IPython.这是已在主版本中修复,但该修复程序并未向后移植到 1.5.1.如果您手动将该补丁应用到 core/management/commands/shell.py,IPython 应该可以正常工作.

django 1.5 doesn't start IPython properly. This is fixed in master, but the fix was not backported to 1.5.1. If you manually apply that patch to core/management/commands/shell.py, IPython should work as expected.

这篇关于使用 Django 1.5 和 IPython 获取 NameError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆