我一直在尝试在我的图像缩略图上放置一个超链接,这会将用户带到一个完整尺寸的图像。但我不断收到错误。
这里如图所示, scribblemedia 是一个 ForeignKey 用于涂鸦
模型.py
class ScribbleMedia(models.Model):
media = models.FileField(upload_to=get_file_path)
def __unicode__(self):
return self.media
def find_typecheck(self):
filename = self.media.name
try:
ext = filename.split('.')[-1]
imgcheck=['jpg','jpeg','png','gif','tiff','bmp']
if ext in imgcheck :
chk='image'
else:
chk='other'
except Exception:
chk='not supported'
return chk
class Scribble(models.Model):
title = models.CharField(max_length=120)
body = models.TextField()
user = models.ForeignKey(User)
media = models.ForeignKey(ScribbleMedia)
def __unicode__(self):
return u'%s, %s' % (self.user.username, self.media)
视图.py
@login_required
def image_page(request,pk):
img=get_object_or_404(ScribbleMedia,pk=pk)
image=img.media
variables= RequestContext(request,{
'image': image
})
return render_to_response('image_page.html',variables)
网址.py
(r"^image/(\d+)/$", image_page),
image_page.html
{% if image %}
<img src= {{ image.url }} />
这是图像缩略图可用的页面
scribble_page.html
{% if scribble.media.media %}
{% if scribble.media.find_typecheck == 'image' %}
{% thumbnail scribble.media.media.url "700x500" crop="center" as im %}
<a href="/image/{{ scribble.media.pk }}/" target="_blank"><img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"></a>
{% endthumbnail %}
{% else %}
do something else
{% endif %}
{% endif %}
它不断给我以下错误:
/image/2/ 处的 TemplateSyntaxError 未闭合标签“如果”。寻找其中之一:elif、else、endif