Reversing a URL with optional arguments fails
|Reported by:||Rob Hudson||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I discovered this recently where I wanted a URL to be /detail/ for page 1, and /detail/page-2/ for further pages. I set up the "page-2/" as an optional regular expression and my default had a default kwarg. Reversing this URL without the page worked but not when I added the page argument. So I created some test cases and found some interesting results...
The first test case without the '$' terminated URL, results in:
AssertionError: '/optional/1/2' != '/optional/1/2/'
With the '$' terminated URL, it results in an exception, which is what I was triggering in my project, it seems:
AssertionError: '/optional/1/2/' != <class 'django.core.urlresolvers.NoReverseMatch'>
I'll attach the testing changes...
Change History (9)
comment:1 Changed 6 years ago by
|Patch needs improvement:||unset|
comment:2 Changed 6 years ago by
|Triage Stage:||Unreviewed → Accepted|