#31809: Regex URL patterns with conditional capture break default values in view
functions
-----------------------------------------+------------------------
Reporter: scorchio | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Hello,
When I use a conditional, named capture group in a URL pattern with a view
function which has a default value, the default value is not adhered to.
For a full example, this minimal Django app below will act like the
following:
- On visiting /this, it will print "this" (as expected).
- On visiting /that, it will print "that" (as expected).
- On visiting / (=not specifying anything), instead of falling back to the
default view parameter "this", I get None.
{{{
import sys
from django.conf import settings
from django.conf.urls import url
from django.core.management import execute_from_command_line
from django.http import HttpResponse
settings.configure(
DEBUG=True,
ROOT_URLCONF=__name__,
)
def routing_example(request, choices="this"):
return
HttpResponse('<html><body>{text}</body></html>'.format(text=choice))
urlpatterns = [
url(r'^(?:(?P<choice>(this|that)))?$', routing_example),
]
if __name__ == '__main__':
execute_from_command_line(sys.argv)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31809>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.858d47fa5959340b10079b56130ac458%40djangoproject.com.