Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting NameError with Django 1.5 and 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.

like image 500
Jim Avatar asked Apr 07 '13 20:04

Jim


1 Answers

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.

like image 181
minrk Avatar answered Sep 21 '22 04:09

minrk