Hello, folks.
I started back at the top of the manual again and I am understanding much
more by progressing slowly and with copious notes. So far, so good.
However, I have come across a bit of a puzzling issue with the latter part
of the "images" tutorial. After creating the dbases, uploading some images
via appadmin, and then adding the app's core in default.py:
def index():
images = db().select(db.image.ALL, orderby=db.image.title)
return dict(images=images)
def show():
image = db.image(request.args(0,cast=int)) or redirect(URL('index'))
db.post.image_id.default = image.id
form = SQLFORM(db.post)
if form.process().accepted:
response.flash = 'your comment is posted'
comments = db(db.post.image_id==image.id).select()
return dict(image=image, comments=comments, form=form)
def download():
return response.download(request, db)
And then creating the default/index.html:
{{extend 'layout.html'}}
<h1>Current Images</h1>
<ul>
{{for image in images:}}
{{=LI(A(image.title, _href=URL("show", args=image.id)))}}
{{pass}}
</ul>
And finally, the default/show.html:
{{extend 'layout.html'}}
<h1>Image: {{=image.title}}</h1>
<center>
<img width="200px"
src="{{=URL('download', args=image.file)}}" />
</center>
{{if len(comments):}}
<h2>Comments</h2><br /><p>
{{for post in comments:}}
<p>{{=post.author}} says <i>{{=post.body}}</i></p>
{{pass}}</p>
{{else:}}
<h2>No comments posted yet</h2>
{{pass}}
<h2>Post a comment</h2>
{{=form}}
When the app is called, it behaves as expected in every instance with one
exception: I was figuring that, based on:
<img width="200px"
src="{{=URL('download', args=image.file)}}" />
When the image was displayed in the show.html view, that maybe it would be
tagged with an embedded download link such that passing the mouse over the
image would indicate a link and then clicking the image would trigger a
download action to download the image. This does not occur. The app just
displays the uploaded image with no apparent way to download it (aside from
the usual right-click browser options). In fact, in looking at the app's
structure, I can't see where the download action in the default.py
controller is ever triggered, since all of that =URL('download',
args=image.file)}} doesn't *appear* to cause any action with regard to the
requested image which is being displayed.
Through experimentation I discovered that I can indeed get a download
action of the type which I *expected* to be triggered if I manually look up
the name of the uploaded image file under
applications/images/uploads/<filename> and then pass it to the download
action myself in the address bar:
http://localhost.../images/default/download/<filename>
That's what I was expecting to happen when I clicked on the image (or was
somehow otherwise directed to the download action), but apparently I was
wrong to assume this...?
In any case, how then does the download action get triggered if not by:
<img width="200px"
src="{{=URL('download', args=image.file)}}" />
?
Any pointers, corrections, directions for further reading, etc. would be
sincerely appreciated.
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.