我学习了 Django ORM。如何在我的模板中获取照片?
def index(request):
animal = Animal.objects.all()
return render_to_response('animal.html',
{'animal':animal,},
context_instance=RequestContext(request))
模板:
{{ animal.name }}
{{ animal.photo.all }}
但这不起作用。
楷模:
class Animal(models.Model):
name = models.CharField(max_length=255)
class Photo(models.Model):
photo = models.ImageField(upload_to='media/images')
animal = models.ForeignKey(Animal)