Re: Need help DRYing up urls.py

2008-04-18 Thread Brandon Taylor
In this case, I think I'll be fine, as the templates that would match any of these patterns just contain public, static content, nothing dynamic. However, I will definitely keep the code snippet for future use! Thank you to all who have replied, I really appreciate your help and guidance as I get

Re: Need help DRYing up urls.py

2008-04-18 Thread Marty Alchin
Just a quick word of warning: You're now essentially passing unfiltered user input directly into the template loader. Depending on what content you have in your templates, this may imply a security risk. For instance, if you have a template that hard-codes any secure information, such as system ac

Re: Need help DRYing up urls.py

2008-04-18 Thread Brandon Taylor
Gotcha. Very, very cool. Here's what I did. Please tell me if there's a better way: #in views.py def return_template(request, template): return direct_to_template(request, (template + '.html')) #in urls.py from django.conf.urls.defaults import * from rdk.pages.views import return_template u

Re: Need help DRYing up urls.py

2008-04-18 Thread [EMAIL PROTECTED]
That wouldn't be return template((template))), it should be just the view's name, not actually calling it, and your wrapper function needs to take request, and pass it along to dire3ct_to_template On Apr 18, 3:51 pm, Brandon Taylor <[EMAIL PROTECTED]> wrote: > Sorry, forgot to say that I have imp

Re: Need help DRYing up urls.py

2008-04-18 Thread Brandon Taylor
Sorry, forgot to say that I have imported the view into urls.py from rdk.pages.views import return_template On Apr 18, 2:39 pm, Brandon Taylor <[EMAIL PROTECTED]> wrote: > 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

Re: Need help DRYing up urls.py

2008-04-18 Thread Brandon Taylor
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 url

Re: Need help DRYing up urls.py

2008-04-18 Thread [EMAIL PROTECTED]
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

Re: Need help DRYing up urls.py

2008-04-18 Thread Brandon Taylor
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 O

Re: Need help DRYing up urls.py

2008-04-18 Thread [EMAIL PROTECTED]
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 wa

Re: Need help DRYing up urls.py

2008-04-18 Thread Brandon Taylor
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 as (template) as such: (r'(?P[-\w]+)/$', direct_to_template, {'template' : '% (template)s.html'}), Thanks, Brandon On Apr 18, 11:25 am, "Marty Alchin" <[EMAIL PROTECTED]> wrote

Re: Need help DRYing up urls.py

2008-04-18 Thread Marty Alchin
On Fri, Apr 18, 2008 at 12:17 PM, Brandon Taylor <[EMAIL PROTECTED]> wrote: > (r'?P[-\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

Need help DRYing up urls.py

2008-04-18 Thread Brandon Taylor
Hi everyone, Coming from Rails, I've been naming my templates according to their corresponding URLs. But, since Django's routing is RegEx based, I'm sure there's a better way to do this: urlpatterns = patterns('', (r'^$', direct_to_template, {'template':'home.html'}), (r'^contact/$', dir