Configuring URLs for different views

2010-10-01 Thread simon_saffer
Hi,

I'm completely new to Django so forgive me if this is a dumb question.


In the web site I'm creating many of the pages will not be database
driven.
I am trying to set up my urls.py so that all pages that all extend the
base.html template
can be rendered in the same way. I'm sure that I shouldn't need a
unique pair in urlpatterns
in urls.py for each *.html that I want to show. My attempt at doing
this was to put the following in
urls.py in urlpatterns

(r'^(?P[a-zA-Z0-9]*?\.html?)$', 'mysite.views.showPage')

and then have a views.py in the mysite 'root' with the function

def showPage(request, page):
t = loader.get_template(page)
c = Context({})

return HttpResponse(t.render(c))


How can I achieve something like this?

I'll be grateful for any help I can get.

/Simon

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Re: Configuring URLs for different views

2010-10-04 Thread simon_saffer
Thanks a lot for all your answers.

It turned out that what I'd done above worked but in the template I
was trying to load there was a typo. I had written:
{% extends base.html %} instead of {% extends "base.html" %}

Anyway it was a good thing I posted my question so that I could get
your ideas on better solutions.

Thanks

Simon



On Oct 2, 8:33 pm, Carles Barrobés  wrote:
> I sometimes use the direct_to_template generic view for adifferent
> purpose than yours (test a template), but the same URL pattern might
> be useful to you:
>
>     # test a template
>     (r'^direct/(?P.*)$',
> 'django.views.generic.simple.direct_to_template'),
>
> Although you'd better use a better regex to match the template name
> (like the one you originally used):
>
>   (r'^(?P[a-zA-Z0-9]*?\.html?)$',
> 'django.views.generic.simple.direct_to_template')
>
> You might also want to take a look at the flatpages 
> app:http://docs.djangoproject.com/en/dev/ref/contrib/flatpages/
> which may be an alternative approach to what you are trying to
> achieve.
>
> C.
>
> On 1 Oct, 16:52, bruno desthuilliers 
> wrote:
>
> > On 1 oct, 16:07, simon_saffer  wrote:
> > (snip)
>
> >  My attempt at doing
>
> > > this was to put the following in
> > >urls.py in urlpatterns
>
> > > (r'^(?P[a-zA-Z0-9]*?\.html?)$', 'mysite.views.showPage')
>
> > hint : namedurlsare cool
>
> > > and then have a views.py in the mysite 'root' with the function
>
> > is 'mysite' an app in your project, or is it the project itself ?
>
> > > def showPage(request, page):
>
> > hint: Python coding conventions : use all_lower names for functions
>
> > >     t = loader.get_template(page)
> > >     c = Context({})
>
> > >     return HttpResponse(t.render(c))
>
> > hint : use the render_to_response()
> > hint : use RequestContext if you want your context processors to be of
> > any use
>
> > > How can I achieve something like this?
>
> > Hmmm... What happened with your above attempt exactly ? I guess it
> > didn't yield the expected results, but you don't tell what happened
> > exactly (and when I mean "exactly", it means that if you got a
> > traceback you should post the _whole_ traceback too).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.