Reputation: 345
I've been trying to put a hyperlink on my image thumbnail which would take the user to a full size image. but I keep on getting an error.
here as it shows, scribblemedia is a ForeignKey to scribble
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)
@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)
(r"^image/(\d+)/$", image_page),
{% if image %}
<img src= {{ image.url }} />
This is the page where the image thumbnail is available
{% 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 %}
It keeps on giving me the following error:
TemplateSyntaxError at /image/2/ Unclosed tag 'if'. Looking for one of: elif, else, endif
Upvotes: 1
Views: 467
Reputation: 6179
The if statements in your scribble_page.html are fine. You need to close your if block in your image_page.html template...
{% if image %}
<img src="{{ image.url }}" /> <!-- Also note the added quotations... -->
{% endif %} <!-- This is the line you need to add -->
Upvotes: 4