Sorry... I think that's a little more complicated than what I need, actually. Django already handles searching for the template in all the right locations, so I don't have any problem actually rendering the template, and I shouldn't need to worry about absolute paths. Here's a simplified bit of code from the flatpage view in contrib.flatpages:
DEFAULT_TEMPLATE = 'flatpages/default.html' def flatpage_detail(request, url): # ... f = get_object_or_404(FlatPage, url__exact=url) if f.template_name: t = loader.select_template((f.template_name, DEFAULT_TEMPLATE)) else: t = loader.get_template(DEFAULT_TEMPLATE) So in the Django admin site, if you have a flatpage that you want to use a template other than the default one, you enter the path to the template into the "template_name" field as something like 'flatpages/custom_template.html'. I want the exact same functionality, but I just want the admin site to display a select list of all templates in a given directory instead of a blank text field. So within my templates directory I'd make a directory at "flatpages/templates/" that includes "default.html," "custom_template_a.html," "custom_template_b.html" and so on. I'm just stuck on how to generate a list of those templates to use as choices in the admin site select menu. I want the list to populate based on the actual files that exist in the directory and update itself when new files are added. When you save the model instance, the template name you selected is saved in a column on the model itself and rendering the correct template is no problem. On Fri, Feb 10, 2012 at 4:54 PM, Python_Junkie < software.buy.des...@gmail.com> wrote: > I think I just figured out what you want to do. > > You want one drop down list with all of the templates listed > regardless of which folder the template lives in. > > So, as describe above you would create a dictionary of template_names > by walking through the directories where the templates live > and pass the dictionary back to the drop down list. > > Once the template is selected then you have to render back to the > folder that the selected template lives in. > > You can create a database table with 2 columns , assuming all of the > templates are named uniquely. > > column a contains the nameof all of the templates from the drop down > list. > column b contains the path that the template lives in. > > So, when the user selects the template, the template value is passed > to the view. > > The view can then perform a sql query > > select template_path from table where template ='template_name' > > value=crsr.fetchone() > > full_path=value+template_name > > render(full_path, plus whatever values you want to pass that > template) > > > If you don't want to use a table you could have python walk through > all of the directories until it achieves a match on the template name > > I hope this solves your question -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.