Django - Render A List Of File Names To Template
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 sam
Solution 1:
Your dictionary is not a valid python code because you are using "=" instead of ":". It should be:
variables = RequestContext(request,{
'user' : request.user,
'title' : 'something',
'files' : os.listdir('/path/to/gallery')
})
One last thing, listdir expects an abosulte path, you can get the root path of your project with:
ROOT_PATH = os.path.abspath(os.path.dirname(__file__).decode('utf-8')).replace('\\', '/')
Solution 2:
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.
Post a Comment for "Django - Render A List Of File Names To Template"