Re: url template tag, unhelpful when failing
On Fri, Jul 18, 2008 at 3:09 PM, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > On Fri, 2008-07-18 at 19:30 +0200, Mikael Moutakis wrote: >> Hi >> I've running from trunk and recently switched to the NFA-branch. I >> found that the URL templatetag is unhelpful when failing to match a >> url. I patched my own copy of the function URLNode in >> django.template.defaulttags to return a more helpful error message >> instead of a empty string. Should I file a ticket with the patch or >> should I add the solution as a django snippet instead? Sorry, if this >> is a stupid question, but I'm new to this. I modified the last 3 lines >> of the function below. > > > The basic design rule is that template tags should always fail silently > if there's an error. Some templates and applications rely on this > behaviour. So a change like this runs against that principle. > In other words, a patch like that will likely not get applied. However, others may find it useful, so a snippet may be the way to go. However, I wouldn't just post your patch as a snippet, but post a full working tag that would be added to a users app, which can then be used in place of the one that ships with Django. If your interested in more specifics as to why Django has chosen silent failure, search the list archives. Seems there was a recent discussion about it. -- Waylan Limberg [EMAIL PROTECTED] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: url template tag, unhelpful when failing
On Fri, 2008-07-18 at 19:30 +0200, Mikael Moutakis wrote: > Hi > I've running from trunk and recently switched to the NFA-branch. I > found that the URL templatetag is unhelpful when failing to match a > url. I patched my own copy of the function URLNode in > django.template.defaulttags to return a more helpful error message > instead of a empty string. Should I file a ticket with the patch or > should I add the solution as a django snippet instead? Sorry, if this > is a stupid question, but I'm new to this. I modified the last 3 lines > of the function below. The basic design rule is that template tags should always fail silently if there's an error. Some templates and applications rely on this behaviour. So a change like this runs against that principle. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com 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 -~--~~~~--~~--~--~---
url template tag, unhelpful when failing
Hi I've running from trunk and recently switched to the NFA-branch. I found that the URL templatetag is unhelpful when failing to match a url. I patched my own copy of the function URLNode in django.template.defaulttags to return a more helpful error message instead of a empty string. Should I file a ticket with the patch or should I add the solution as a django snippet instead? Sorry, if this is a stupid question, but I'm new to this. I modified the last 3 lines of the function below. class URLNode(Node): def __init__(self, view_name, args, kwargs): self.view_name = view_name self.args = args self.kwargs = kwargs def render(self, context): from django.core.urlresolvers import reverse, NoReverseMatch args = [arg.resolve(context) for arg in self.args] kwargs = dict([(smart_str(k,'ascii'), v.resolve(context)) for k, v in self.kwargs.items()]) try: return reverse(self.view_name, args=args, kwargs=kwargs) except NoReverseMatch: try: project_name = settings.SETTINGS_MODULE.split('.')[0] return reverse(project_name + '.' + self.view_name, args=args, kwargs=kwargs) except NoReverseMatch: if settings.DEBUG: return u"/NOURLMATCH %s %s %s" % (self.view_name, args.__str__(), kwargs.__str__()) return "" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com 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 -~--~~~~--~~--~--~---