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.
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… 🤔 On Mon, 19 Sept 2022 at 14:07, Meiyer <interd...@gmail.com> wrote: > Hi, > > I feel there is a use case that the `path()` function does not address and > thus requires to switch over to `re_path()` which immediately adds a lot of > additional and error-prone syntax. > > Often there is a need to capture a URL parameter which can be optional > into the view’s kwargs. In terms of path() syntax, this could be > accomplished by simply allowing, e.g., <int:param?>. However, I am not sure > how to handle the forward slash that would usually appear after the > parameter, and I don’t know how difficult it would be to amend the current > implementation to support this feature. > > By the way, if there was a discussion about this before, I couldn’t find > it. Please point me to it if there was. > > -- > 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/818f30d8-308b-4860-b861-7c7dde9b7aaan%40googlegroups.com > <https://groups.google.com/d/msgid/django-developers/818f30d8-308b-4860-b861-7c7dde9b7aaan%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAJwKpyTxa291LBc17H7%3DhpdHy3F_sSj2yPz76ncphMa7Mf4qZQ%40mail.gmail.com.