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

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

问题描述

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

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

NameError:未定义名称'forms'。

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



有没有人遇到这个问题?如果是这样,你知道为什么会发生,是否有一个解决方案?



我应该补充说,我以前在过去创建类的问题REPL,直到我在类中创建一个元类并定义了一个app_label变量。



谢谢。

解决方案

django 1.5不正确启动IPython。这是固定在主站,但修复程序未被返回到1.5.1。如果您手动将该修补程序应用于core / management / commands / shell.py,则IPython应按预期工作。


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.

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?

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.

Thanks.

解决方案

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天全站免登陆