楷模:
class Design(models.Model):
title = models.CharField(max_lengt=255)
class DesignImg(models.Model):
design = models.ForeignKey(Design)
img = models.ImageField(upload_to="project_images")
意见:
def index(request):
d = Design.objects.all()
return render_to_response('index.html',{'d':d},context_instance=RequestContext(request))
模板(这是不正确的):
{% for a in d %}
<img src="{{ a.img.url }}"/>
{% endfor %}
如何显示我img
的所有模板?