我在跟踪本教程,我被困住了。
我已经定义了本教程中提到的所有内容,但是我得到了以下错误:
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请告诉我我的错误。谢谢
发布于 2014-03-19 03:35:41
很难说,因为您没有发布任何示例代码,但在当前命名空间中未定义此变量时,python将给出global name 'variable' is not defined语句。
如果您直接从教程中工作,并且错误是在views.py中抛出的,那么我的猜测是您忘记了在这个文件中导入模型。
尝试:
from mttp.models import Genremttp是你的应用程序的名字。我只是从教程网站抓取,但你可能会或不可能有不同的设置。
https://stackoverflow.com/questions/22485084
复制相似问题