采取这样一个简单的观点:
def my_gallery(request):
images= ?
t = Template("<html><body>Here my images from XY {{ images }}.</body></html>")
html = t.render(Context({'images': ? }))
return HttpResponse(html)
如何定义变量图像/我需要填写上下文 所以Django给我看:
1张图片 超过1张图片 1声音文件 超过1个声音文件
网站my_gallery
谢谢!
答案 0 :(得分:0)
我猜你想知道什么......
#/appname/model.py
from django.db import models
class MyImages(models.Model):
images = models.ImageField(upload_to='/upload_path/')
#/appname/views.py
from appname.models import MyImages
from django.template.context import RequestContext
from django.shortcuts import render_to_response
def my_gallery(request, template='gallery.html'):
obj_images= MyImages.objects.all()
kwvars = {
'images': obj_images,
}
return render_to_response(template, kwvars, RequestContext(request))
#gallery.html
...
{% for image in images %}
{{ images.url }}
{% endfor %}