I understand the concept of that, but I'm having an issue with
importing the view function into my urls.py. Here's what I have so
far:

#in views.py
from django.views.generic.simple import direct_to_template

def return_template(template):
    return direct_to_template(template % '.html')

#in urls.py
urlpatterns += patterns('compliance-bsa/',
                        (r'(?P<template>[-\w]+)/$',
return_template((template))),
)

This gives me an error: Error while importing URLconf
'rdk.pages.urls': name 'template' is not defined. I thought (?
P<template>) gave me (template) that I can use later in views, no?

Thank you,
Brandon

On Apr 18, 2:12 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Yes, instead of having it use a generic directly in the urlconf, you
> would have it go to the view, the view would do what you
> need(specifically doing that simple substitution), and then have it
> return django.views.generic.simple.direct_to_template, remember views
> are just functions, if you need an example let me know and I will
> write one up.
>
> On Apr 18, 3:10 pm, Brandon Taylor <[EMAIL PROTECTED]> wrote:
>
> > Hi Alex,
>
> > Thanks for the advice. Still being new to Django, where would such a
> > wrapper function need to exist? In the views.py? models.py?
>
> > I'm guessing it would need to be something along the lines of:
>
> > def replace_template_var(template):
> >     return template % '.html'
>
> > ? Please advise,
> > Brandon
>
> > On Apr 18, 1:34 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> > wrote:
>
> > > Direct_to_template does not substitute the template var in to the
> > > template param, you will need to write a simple wrapper to do
> > > something like this.
>
> > > On Apr 18, 12:35 pm, Brandon Taylor <[EMAIL PROTECTED]> wrote:
>
> > > > Ah. I see now. It's matching the first part of the URL, but it doesn't
> > > > seem to want to substitute the named parameter <template> as
> > > > (template) as such:
>
> > > > (r'(?P<template>[-\w]+)/$', direct_to_template, {'template' : '%
> > > > (template)s.html'}),
>
> > > > Thanks,
> > > > Brandon
>
> > > > On Apr 18, 11:25 am, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
>
> > > > > On Fri, Apr 18, 2008 at 12:17 PM, Brandon Taylor
>
> > > > > <[EMAIL PROTECTED]> wrote:
> > > > > >  (r'?P<template>[-\w]+/$', direct_to_template, {'template' : '%
> > > > > >  (template)s.html'}),
>
> > > > > >  ...and received an error saying:
> > > > > >  Error while importing URLconf 'rdk.pages.urls': nothing to repeat
>
> > > > > You're missing parentheses around the group you're trying to capture.
> > > > > Without them, Python thinks the first question mark is a "zero or one
> > > > > instances" instruction, but there's nothing befor it to match against.
> > > > > Try this:
>
> > > > > r'(?P<template>[-\w]+)/$'
>
> > > > > -Gul
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to