lundi 1 septembre 2014

Django: Page for each image in folder


Vote count:

0




I have a model which is a directory to a folder with images in (in order of filename), to display this I have this in the URL:



url(r'^(?P<slug>[^\.]+)', 'Main.views.read'),


and for read it will display all images with this (not too sure if it's the best way but it works so it's OK in my books):



def read(request, slug):

dir_name = slug
path = os.path.join(settings.MEDIA_ROOT, dir_name)
images = []
for f in os.listdir(path):
if f.endswith("jpg") or f.endswith("png"):
images.append("%s%s/%s" % (settings.MEDIA_URL, dir_name, f))

return render(request, 'read.html', {
'images': images,
})


But I also want the user to be able to go image by image depending on how many pictures are found, how would I go about doing this? Should I make a whole new view or find a way to find if the user goes on a url like so:



url(r'^(?P<slug>[^\.]+)\(?P<page>\d+(?:\.\d+)?)', 'Main.views.read'), # different views.* if needed(?)


asked 27 secs ago







Django: Page for each image in folder

Aucun commentaire:

Enregistrer un commentaire