python - I keep getting the following error in django: "UnboundLocalError at /myapp/" -
i facing error in django python:
"unboundlocalerror @ /myapp/" local variable 'album' referenced before assignment
i created class in models.py file , import in views facing error
here complete code of both files:
models.py
from django.db import models django.db import models class album(models.model): artist = models.charfield(max_length=250) title = models.charfield(max_length=500) gender = models.charfield(max_length=100) def __str__(self): return self.artist+'--'+self.title views.py
from django.http import httpresponse .models import album def myapp(request): all_albums = album.objects.all() title = album.artist html = '' album in all_albums: url = '/myapp/' + str(album.id) + '/' html += '<a href="' + url + '">' + title + '</a><br>' return httpresponse(html)
copy totally , paste in view
from django.http import httpresponse .models import album def myapp(request): all_albums = album.objects.all() html = '' al in all_albums: url = '/myapp/' + str(al.id) + '/' html += '<a href="' + url + '">' + al.artist + '</a><br>' return httpresponse(html)
Comments
Post a Comment