There are 2 approaches:

- Think data structures instead, and put all this logic on your view,
such that the template just needs to iterate thru one variable to
build the menu. Something like passing in the template context:

menu = [{'name': 'django', 'text': 'Official Django Site', 'url':
'http://djangoproject.com/'}, ...]

- Write template tags for building the menu. This is the cleanest
approach, as you comprise all menu logic in a reusable tag.

On 20 ago, 18:00, Kevin <[email protected]> wrote:
> I come from the world of mod_python and really enjoyed the PSP
> template system, where I can embed Python code directly in my template
> for dynamically generating menus and such.
>
> What is the recommended method of calling a PSP template from inside
> Django and rendering it?
>
> Here is a sniplet of code I am trying to convert over to the Django
> template engine, but cannot figure out the best method:
>
> for name, text, url in menu_items:
>     attr = ""
>     if name == hlight:
>         attr = "class='highlight'"
>     # begin
> %>
>             <tr><td <%=attr%>><a href="<%=url%>"><%=text%></a></td></
> tr>
> <%
> # end
> %>
>
> And yes, this menu code is from the mod_python example site.  Also
> does Django include an example fully working site to display most, if
> not all of it's abilities?  The example site which mod_python includes
> is very simple, but is a great starting point for a website.
>
> mod_python's example site is here:  http://modpython.org/examples/
>
> I really think having such an example for django would be good as
> well.  I am actually in the process of basically re-creating this
> example site in django to learn how django works and how it differs
> from mod_python coding.

-- 
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?hl=en.

Reply via email to