Hello, I'm pretty new with django, exactly the same than with python, and 
after reading a few tutorials and make a very simple django site, I have a 
django/python question... 


I made this script in python: 

<code> 

import os 
import random 

url 
='/home/usuario/django/projects/volei/volei/static/img/stories/fotos_jugadoras/'
 

directorios = os.listdir(url) 

lista_ficheros = [] 
for direc in directorios: 
url_ficheros = url+direc 
lista_ficheros.extend(os.listdir(url_ficheros)) 

r = random.choice(lista_ficheros) 

</code> 

And it do exactly what I want, get a pic at random from a few folders. 

Ok, I have a few templates, and all of them inherit from base.html, and in 
base.html I want to add this random pics... 

I think the script goes in the view.py, but I don't know how it can be 
since no view goes directly (and at same time all indirectly) they end in 
base.html... I tried to put all the script in {% %} in the base.html, but 
it doen't work.. 


I will explain briefly what I want to do only in case django or python have 
a easier way to do: 
get random image from a tree folder like this: 
folder/subfolder1/img.jpg 
folder/subfolder2/img2.jpg 
folder/subfolder3/img3.jpg 

I have an slide, and only showing one at once, so the idea was every time 
slide goes to show an image, it will get it from the random script... 

I don't know if I explain myself.. ^^' 

Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/T71GlSb01dwJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to