Question

I was following this tutorial and i got stuck.

I have defined everything as mentioned in the tutorial but i am getting the following error:

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

Please let me know my mistake. Thank you

Was it helpful?

Solution

It is hard to say because you haven't posted any sample code, but python will give the global name 'variable' is not defined statement when this variable is not defined in the current namespace.

If you are working directly from the tutorial, and the error is thrown in views.py, my guess is that you forgot to import the model in this file.

Try:

from mttp.models import Genre

where mttp is the name of your app. I just grabbed this from the tutorial site but you may or may not have it set up differently.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top