Getting NameError with Django 1.5 and IPython

左心房为你撑大大i 提交于 2019-12-09 00:38:02

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/15867678/getting-nameerror-with-django-1-5-and-ipython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!