librelist archives

« back to archive

show images from another folder than static

show images from another folder than static

From:
julio bm
Date:
2012-11-02 @ 19:35
Hi

 i get problems when i do

 img_list = [] for row in os.listdir(the_folder_i_want): 
img_list.append(row) return render_template('index.html', images=img_list)
index.html: {% for i in images %} <img src="{{ i }}"/> {% endfor %} it 
only works when "the_folder_i_want" = 'static' but i want to display 
images from /usb/pictures by example and my app is installed in 
/home/myflask thank you

Re: [flask] show images from another folder than static

From:
pronoyc@gmail.com
Date:
2012-11-02 @ 19:40
http://flask.pocoo.org/docs/patterns/fileuploads/

You are looking for the function:

send_from_directory



On Sat, Nov 3, 2012 at 1:05 AM, julio bm <juliob@gmx.com> wrote:

>  Hi
>
> i get problems when i do
>
>
> img_list = []
> for row in os.listdir(the_folder_i_want):
>     img_list.append(row)
>
> return render_template('index.html', images=img_list)
>
>
>
> index.html:
>
> {% for i in images %}
>   <img src="{{ i }}"/>
> {% endfor %}
>
> it only works when "the_folder_i_want" = 'static'
>
> but i want to display images from /usb/pictures by example and my app is
installed in /home/myflask
>
> thank you
>
>
>


-- 
Regards,

Pronoy Chopra
http://blog.pronoy.in <http://www.pronoy.in/about>/
http://www.twitter.com/pronoyc

Re: [flask] show images from another folder than static

From:
julio bm
Date:
2012-11-09 @ 11:46
i'm sorry but finally i did:

 #deleting
 for file in 'static/pictures'
 os.remove(file)

 #copying
 shutil.copy2('/usb/pictures', 'static/pictures')

 ....
 ....
img_list = [] for row in os.listdir('static/pictures'): 
img_list.append(row) return render_template('index.html', images=img_list)
index.html: {% for i in images %} <img src="{{ i }}"/> {% endfor %} 


----- Mensaje original -----
De: pronoyc@gmail.com
Enviado: 02-11-12 20:40
Para: flask@librelist.com
Asunto: Re: [flask] show images from another folder than static

http://flask.pocoo.org/docs/patterns/fileuploads/ 

 You are looking for the function:
send_from_directory

 On Sat, Nov 3, 2012 at 1:05 AM, julio bm < juliob@gmx.com > wrote:

Hi

 i get problems when i do

 img_list = [] for row in os.listdir(the_folder_i_want): 
img_list.append(row) return render_template('index.html', images=img_list)
index.html: {% for i in images %} <img src="{{ i }}"/> {% endfor %} it 
only works when "the_folder_i_want" = 'static' but i want to display 
images from /usb/pictures by example and my app is installed in 
/home/myflask thank you 

 --

 Regards,
 Pronoy Chopra 
http://blog.pronoy.in http://www.pronoy.in/about /
http://www.twitter.com/pronoyc