> > > One approach is to route two patterns (one with the parameter and one > without) to the same URL. Some duplication but (perhaps) easier to read at > a glance than either an optional `?` operator. >
I thought about that, but it won't work if I want both cases to be named similarly (via the `name` parameter). It also feels as duplicating the same line. > Given that — and the alternative re_path() approach being available — > unless there was a particularly simple implementation on display I'd > likely be sceptical about an addition here… 🤔 > I did a bit of digging in the Django code and in fact it might be quite easy (it is also possible I am missing the elephant). django.urls.resolvers defines the syntax for the path parameters on line 245 [1] and converts the matches to regular expressions on line 290 [2]. Looks like an addition of the '?' to the regex after the closing bracket would do it..? [1] https://github.com/django/django/blob/baf9604ed8fed3e6e7ddfaca2d83c377c81399ae/django/urls/resolvers.py#L245 [2] https://github.com/django/django/blob/baf9604ed8fed3e6e7ddfaca2d83c377c81399ae/django/urls/resolvers.py#L290 -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/9e0828d7-6434-4fd1-b605-8113342fcba9n%40googlegroups.com.