Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6870025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:37:54+00:00 2026-05-27T03:37:54+00:00

I am generating a template for an image gallery page. My approach is as

  • 0

I am generating a template for an image gallery page. My approach is as follows:

  • Host the images from a sub directory of an images folder
    • The image folder will be titled the same as the gallery title
  • The view passes a list of filenames to the template
  • The template loops through the list and creates img tags

So my view would be

def some_gallery(request):
    #LOGIC TO GET A LIST OF FILENAMES

    variables = RequestContext(request,{
        'user' : request.user,
        'title' : 'something',
        'files' : fileList
    })
    return render_to_response('gallery_template.html',variables)

And the template

....
{% for file in files %}
    <img src="/path/to/images/{{ title }}/{{ file }}">
{% endfor %}
....

The problem I am running into is that Django is putting up a 500 error when I try to use the os.listdir function. How can I get the file list that I need??

Problematic version of the view which is giving the 500 error

def some_gallery(request):

    variables = RequestContext(request,{
        'user' : request.user,
        'title' : 'something',
        'files' : os.listdir('/path/to/gallery')
    })
    return render_to_response('gallery_template.html',variables)

Also I should note that the file path does work, so if I go directly to the url, I get just the image as expected.

EDIT: Fixed the typos in code samples

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:37:54+00:00Added an answer on May 27, 2026 at 3:37 am

    I got it sorted out. My methods were correct, so anyone looking to do this type of thing, the code samples should work.

    The problem that I had was that Django was tripping up on the listdir function call due to some problems accessing the file path that was provided. I made sure the directory permissions and path was correct and it worked.

    Thanks to those that helped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am generating PDF/HTML report from a BIRT template. I am using visibility property
I am generating an email with dynamic content from a Haml template which parses
I'm trying to create a breezebrowser template (used for generating image galleries locally, outputs
I need a way of generating a word document (from a template or something)
I am actually generating some xml from haml template, using Padrino Framework. There are
Im generating a report from a template html file in my program. It resides
When I'm generating/refreshing my model from the database, how do I specify which template
I'm generating a T4 template using the properties of my data class generated from
Is there a good free plugin for generating a template for Nunit test for
I am generating a data template in C#. With the help of the good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.