url templatetag should raise exception on invalid path
|Reported by:||oliver.andrich@…||Owned by:||adrian|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I just stumbled across the fact, that the url templatetag silently accepts any path to a view - no matter if it exists or not. In the module django.template.defaulttags I have seen, that after processing the templatetag an URLNode is generatet and afterwards rendered.
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('.') return reverse(project_name + '.' + self.view_name, args=args, kwargs=kwargs) except NoReverseMatch: return ''
The last try-catch-block which catches the second NoReverseMatch exception is causing the troubles. At least in my eyes.
I would find it much more convenient if I actually get the exception when I cause such an error. This would have saved my some time today, as I created such an error during my Django studies.
Change History (10)
Changed 9 years ago by oliver.andrich@…
comment:1 Changed 9 years ago by mtredinnick
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Resolution set to wontfix
- Status changed from new to closed
comment:4 Changed 9 years ago by kcarnold
- Resolution wontfix deleted
- Status changed from closed to reopened
Changed 9 years ago by kcarnold
comment:5 Changed 9 years ago by SmileyChris
- Has patch set
- Triage Stage changed from Unreviewed to Design decision needed