Thanks Malcolm. I did some testing and the listdir function returns extremely quickly so I don't think it's a big deal. But this will come in handy if the gallery grows much larger. Thanks again.
On Fri, Mar 7, 2008 at 8:26 AM, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > > On Fri, 2008-03-07 at 08:16 -0500, Prof. William Battersea wrote: > > Hello, > > > > I'm working on a photo gallery for a user. I wanted to make it dead > > easy for him to create the gallery and upload photos. Right now, each > > time a gallery page is viewed, I look at the directory where the > > thumbnails are stored using listdir and slice the resulting list > > depending on what page the user is on. I populate the template with > > these images. I did it this way so he could delete and add images > > right from his FTP software without working about removing them from > > html pages, et c. > > > > The page traffic isn't too high (maybe 20k views a year). > > > > Is this bad practice? Can anyone suggest a better alternative? > > It's not bad practice if the load is acceptable. > > Statically caching the directory listing is only going to be possible if > you have some way to invalidate the cache when a new file is added. That > could be a little fiddly on something that is accessed via FTP. Not > impossible, since most operating system's have a way to monitor a > directory for change, but it can be fiddly to set up. > > You could however, speed up detecting changes. You cache the directory > listing in your view. Write it out to a file, or using Django's caching > infrastructure. Then each time the view is called, look at the mtime of > the directory (I'm assuming a POSIX-like filesystem here). That should > change each time a file is added (not true for all network-mounted > filesystems, so experiment first). If the mtime is older than your > cached directory listing, you don't need to list the directory contents > again and can just compute results based on the cached version. > > Regards, > Malcolm > > -- > Save the whales. Collect the whole set. > http://www.pointy-stick.com/blog/ > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---