Django mptt教程错误

时间:2014-03-18 16:17:51

标签: python django python-2.7 django-mptt

我跟着this tutorial而且我被卡住了。

我已经定义了教程中提到的所有内容,但是我收到以下错误:

NameError at /genres/
global name 'Genre' is not defined
Request Method: GET
Request URL:    http://127.0.0.1:8000/genres/
Django Version: 1.6.2
Exception Type: NameError
Exception Value:    
global name 'Genre' is not defined
Exception Location: /home/abhishek/projects/mptt/mpttsample/mpttmodel/views.py in show_genres, line 4
Python Executable:  /home/abhishek/projects/mptt/bin/python
Python Version: 2.7.3
Python Path:    
['/home/abhishek/projects/mptt/mpttsample',
 '/home/abhishek/projects/mptt/local/lib/python2.7/site-packages/django_mptt-0.6.0-py2.7.egg',
 '/home/abhishek/projects/mptt/lib/python2.7/site-packages/django_mptt-0.6.0-py2.7.egg',
 '/home/abhishek/projects/mptt/lib/python2.7',
 '/home/abhishek/projects/mptt/lib/python2.7/plat-linux2',
 '/home/abhishek/projects/mptt/lib/python2.7/lib-tk',
 '/home/abhishek/projects/mptt/lib/python2.7/lib-old',
 '/home/abhishek/projects/mptt/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/home/abhishek/projects/mptt/local/lib/python2.7/site-packages',
 '/home/abhishek/projects/mptt/lib/python2.7/site-packages']
Server time:    Tue, 18 Mar 2014 11:07:13 -0500

请让我知道我的错误。谢谢

1 个答案:

答案 0 :(得分:1)

很难说因为你还没有发布任何示例代码,但是当当前命名空间中没有定义此变量时,python将给出global name 'variable' is not defined语句。

如果您直接从本教程开始工作,并且views.py中出现错误,我猜您忘记在此文件中导入模型。

尝试:

from mttp.models import Genre

其中mttp是您应用的名称。我只是从教程网站上抓住了这个,但你可能会或可能不会以不同的方式设置它。