It would be really good if we could improve the errors provided when Django can't do reverse().
For example: >>> reverse('i_dont_exist') NoReverseMatch: Reverse for 'i_dont_exist' with arguments '()' and keyword arguments '{}' not found. In this case, it would be nicer to have something like: NoURLPattern: No patterns specified for 'i_dont_exist'. Alternatively, if NoReverseMatch listed the patterns it tried (similar to template loader post-mortem given on TemplateDoesNotExist which shows the folders tried) then a new error message would be unnecessary: NoReverseMatch: Reverse for 'i_dont_exist' with arguments '()' and keyword arguments '{}' not found (patterns tried: []). As for regex patterns that can't be reversed, it would nice to improve the errors or improve the docs. The docs state that: > The main restriction at the moment is that the pattern cannot contain > alternative choices using the vertical bar ("|") character. Upon reading this, I expected that Django would warn me if I tried to reverse a pattern with a '|' in it. However, it's sometimes possible url(r'^fruit/(bananas|apples)$', some_view, name='fruit'), >>> reverse('fruit', args=['bananas']) '/fruit/bananas' There's also the issue that there are other ways of expressing alternatives that produce NoReverseMatch, although the docs don't really say that these are problematic: url(r'^fruit(/location/(?P<location>[a-z]+))?(/name/(? P<function>[a-z]+)/)?$', some_view, name='fruit_with_alternative_groups'), >>> reverse('fruit_with_alternative_groups', kwargs={'location': 'london', 'name': 'apples'}) NoReverseMatch: Reverse for 'fruit_with_alternative_groups' with arguments '()' and keyword arguments '{'location': 'london', 'name': 'apples'}' not found. It would be great for the error to mention that I've used '?' which stopped reversing working. Sure, I could have multiple URL patterns named 'fruit_with_alternative_groups', but if there's only one (or all the patterns have this problem) then we could be more helpful. TL;DR: 1. It'd be nice to know how many patterns were tried by reverse(). 2. It'd be nice to get a warning when users try to reverse patterns that contain alternatives with '?' or '?' (or others). 3. It'd be good to clarify the docs as to what patterns are reversible. Thoughts? I'll open bugs, whip up a patch or two if people are interested. -- 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 django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.