UnboundLocalError at /Menu/ local variable 'Menu' referenced before assignment
- Post By Mike Hunt Is Bald
- 4 years ago
I am having this problem when I trying to open my Menu page, searched online and they suggested to add "global Menu" after Def. I did it and it works! So now the code is like this.
def index(request):
global Menu
Menu = Menu.objects.all()
return render(request, 'index.html', {'Menu': Menu})
BUT then after i refresh the page it will have another error which is AttributeError at /Menu/
'QuerySet' object has no attribute 'objects'
So everytime i wanted my page to load i have to Ctrl + S my views.py file and the server will reload and then I can see my site for only once!