On Tue, 2006-08-15 at 17:47 +0900, Sean Schertell wrote:
[...]
> I'd really like to use Django templates and stay DRY by using the  
> same base template for my static pages as I do for any apps in the  
> site. But I'm a little bit put-off by the "flatpages" middleware  
> because it store the content in a database -- seems to complicate  
> things unnecessarily (and seems to require a separate base template  
> too).
> 
> Soo.... what's a boy to do?
> 
> Ideally, I want something like this:
> 
> mysite/
>       apps/
>               blog/
>                       ...
>       templates/
>               static-page1.py
>               static-page2.py
>               static-page3.py
>               static-page4.py
>               static-page5.py
>               static-page6.py
>               blog/
>                       view.py
>                       list.py
> 
> (or something)

Aargh, my eyes! 

What are all these *.py things doing under templates/ ? *shudder*.

Seriously, get view.py and list.py out of there and back up into an
application directory. Keep only your templates under templates (and
since they aren't Python files, call them something that gives you a
clue to that. ".html" endings are common and I've used '.tmpl' in one
project).

OK, that being said, what you want to do probably isn't that hard. I'm
assuming you are happy creating all this static HTML by hand or with
another program or by magic or something. So your static templates would
look like

        {% extends "site-base.html" %}
        {% block content %}
        
        <!-- static HTML content goes here -->
        
        {% endblock %}
        
This assumes that you have a "content" block in site-base.html that you
are going to fill with your page content. Customise to taste, of course.
        
Now you just need an easy way to serve those pages. Well, they have no
need for anything context specific, so presuming you have a way to map
URLs to the right template name, write a simple view that does something
like

        def static_view(request, template_name):
            return render_to_response(template_name, Context({}))
        
(I cheated a lot here; you may have to do some more work to turn the URL
into the right template name.) All you are doing is loading up the right
template, having the base stuff substituted in and rendering the result.
If it really is that simple that you can work out the template name from
the URL automatically, then just use the
django.views.generic.simple.direct_to_template() generic view function,
since it is a slightly enhanced version of what I wrote above.

Hopefully that will give you some ideas you can work with.

Best wishes,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to