On Oct 13, 4:09 pm, Jason <[EMAIL PROTECTED]> wrote:
> Hey everyone--
>
> I've got a predominantly static site that I need to serve through
> Django, at least until I can convert more of it over properly. Yes, I
> know this is discouraged, but it's the only way I'm going to be able
> to move forward w/this project....
>
> I cribbed this line:
>
> urlpatterns += patterns('django.views.generic.simple',
> (r'(?P<template>.*)', 'direct_to_template'),
> )
>
> ...from here: http://www.djangosnippets.org/snippets/346/
>
> ...and it works hunky-dory for most everything-- however, it doesn't
> catch assumed index pages (going tohttp://www.mysite.comgives a
> "template doesn't exist" error; going tohttp://www.mysite.com/index.html
> works fine....)
>
> Further down that "snippets" page someone posted the following:
>
> * (r'^(.*)/$', lambda request, path: direct_to_template(request,
> "%s/index.html" % (path,))),
> * (r'^(?P.*)$', direct_to_template),
>
> ...but I've had no luck w/either of those.
>
> Anyone had any experience w/this?
Hi Jason,
Can't say I've had experience with this directly, but here's my
suggestions:
First, you'll need to set APPEND_SLASH=False in your settings
Next, the trick is that you can pass an iterable of templates to try
rather than a single template, something like:
from os.path import join
from django.templates.generic.simple import direct_to_template
def serve(request, path):
paths = (join(path, 'index.html'), path)
return direct_to_template(request, paths)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---