Hi Anthony, sorry about the late reply. Thank you very much for your
detailed answers.
On Sunday, July 26, 2015 at 5:46:05 AM UTC-7, Anthony wrote:
>
> First, three corrections:
>
> - The upload field does not name the stored file the same as the name
> of the uploaded file. The stored file gets renamed, with the new name
> including an encoded version of the original filename (which gets decoded
> upon retrieveal). It is this new filename that actually gets stored in the
> upload field (the file itself is stored on the filesystem).
> - The attribute after a table name is a field name, not the name of an
> uploaded file, so you would do db.image.file (db.image.water makes no
> sense, as the table does not include a field named "water").
> - The URL argument passed to the download function to indicate which
> file to download must be the filename stored in the upload field, not a
> Field object.
>
> So, to display a given image, you must somehow be able to query the
> database to retrieve the image you want, and then access the "file" field
> of that record to get the filename, which you will then pass as a URL arg
> to the download function. For example:
>
> In a controller:
>
> row = db(db.image.title == 'some title').select().first()
>
> In the view:
>
> <img src="{{=URL('default', 'download', args=row.file)}}
>
> Anthony
>
> On Sunday, July 26, 2015 at 12:41:06 AM UTC-4, michael sun wrote:
>>
>> I build a table:
>>
>> db.define_table('image',
>> Field('title', unique=True),
>> Field('file', 'upload'),
>> format = '%(title)s')
>>
>> then upload a image called 'water'.
>>
>> in index.html, I wrote:
>> <img src="{{=URL('download',args=db.image.water)}}" />
>>
>> but then it gives me the error:
>>
>> <type 'exceptions.AttributeError'>()
>> Function argument list
>>
>> (self=<Table image (id,title,file)>, key='water')
>> Code listing
>>
>> 343.
>> 344.
>> 345.
>> 346.
>> 347.
>> 348.
>>
>> 349.
>> 350.
>> 351.
>> 352.
>>
>>
>> def __getattr__(self, key):
>> try:
>> return self.__dict__.__getitem__(str(key))
>> except:
>> raise AttributeError
>>
>>
>> def __setitem__(self, key, value):
>> self.__dict__.__setitem__(key, value)
>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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/d/optout.