Go to Google Groups Home    Django developers
Re: Reverse URL lookup implementation

Jacob Kaplan-Moss <ja...@jacobian.org>

I just had another thought on this:

On Apr 6, 2006, at 3:24 PM, Adrian Holovaty wrote:

> Ideally there'd be a template-tag interface to this. Something like:

>     {% link 'path.to.month_view' 2005 'apr' %}
>     {% link 'path.to.person_view' state='il' name='adrian' %}

One thing we could do -- to make this even easier -- would be to grab  
data from an object passed into the {% link %} tag.  So in your  
example urlconf::

        (r'^people/(?P<state>\w\w)/(?P<name>\w+)/$', 'path.to.person_view'),

If a Person object had ``state`` and ``name`` attributes, you could do::

        {% link path.to.person_view person %}

(where ``some_person`` is an object in the context) as a shortcut to::

        {% link path.to.person_view state=person.state name=person.name %}

That way if you set up your URLconfs in a logical manner -- I'd bet  
90% of my urlconfs already work this way -- the shortcut version  
would Just Work™.

Jacob