Hi folks --

While working on some URL-related issues, I ran across a pretty big
problem with having ``{% url %}`` propagate ``NoReverseMatch`` up into
the templates: if it does that, there's no way to have "optional"
links.  The perfect example is #7810 and the admin docs: if the URLs
for the admin doc views are installed, the admin should show a
(correct) link to the docs; if they're not installed, the link
shouldn't be there. Unfortunately, with the current ``url`` tag, there
isn't any way to make this work.

I started poking at it, and it turned out to be *very* easy to add a
``{% url ... as varname %}`` syntax to capture the URL into a variable
for later use. As a side effect, I made this syntax *not* raise errors
but instead return an empty string. This makes for a very natural
use::

    {% url django-admindocs-docroot as docroot %}
    {% if docroot %}
        <a href="{{ docroot }}">Documentation</a>
    {% endif %}

Patch here: 
http://code.djangoproject.com/git/?p=django;a=commitdiff;h=6c7d85a3cf6a3c7b161d960f86ea1cb111ded605

So: I know this is technically a "feature addition," but it makes the
fixes to some silly bugs far easier. Are there any objections to me
sneaking this into 1.0?

Jacob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to