Hi Uwe,

You might be able to leverage the 'url' template tag which comes with
django?

e.g. For the 'add observation' example above, if you pass in the
country code as part of the context you return in your view(s), or
leverage middleware to automatically add it to every response based on
the request path, then something like the below might mitigate the
need to write a custom template tag?

# Name the url in urls.py
# Assuming your view is called 'add_observation' and it accepts a
parameter 'country_code'

url(r'/(?P<country_code>[a-zA-Z]{2})/observations/add/$',
'add_observation', \
        name='add_observation'),

You can then use the 'url' template tag to reference the view

<a href="{% url add_observation country_code=country_code %}"> Add
Observation </a>

This is an interesting problem, please do let us know how you solve it
in the end :)

John

p.s. I haven't tested the above, the regex might be dodgy ;)


On Aug 26, 1:16 pm, bruno desthuilliers
<bruno.desthuilli...@gmail.com> wrote:
> On 26 août, 13:27, Uwe Schuerkamp <uwe.schuerk...@gmail.com> wrote:
>
> > Thanks Bruno,
>
> > I'll look into the custom template tags you mentioned.
>
> Well, the way I see it you should first investigate the middleware
> part - that's probably where you'll get the most relevant infos. The
> templatetag part was mostly here to help with formatting etc - IOW to
> factor out template logic.
>
> > I had no idea
> > when I started out with this project that I'd be knee deep into
> > advanced django after a couple of weeks ;-)
>
> I wouldn't label custom templatetags as "advanced" - it's very
> straightforward, basic stuff - at least once you've written a couple
> ones !-) More seriously, I fail to see how one could write a
> maintainable non-trivial django project without custom templatetags,
> so this is something you have to learn anyway, and there's really no
> magic involved.
>
> > BTW, can you recommend the "pro django" book?
>
> Never heard of it, sorry... From the TOC and reviews it looks like it
> might be an interesting reading if you don't already master advanced
> Python stuff like metaclasses and the descriptor protocol, but that's
> all I can say without actually reading the book.
>
> @++
> B.

-- 
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.

Reply via email to