I'd also be -1. There are two good alternatives already, which are both more flexible. No need to add a third way.
On Sun, Oct 2, 2022 at 8:35 AM Carlton Gibson <carlton.gib...@gmail.com> wrote: > Hi. > > Re-reading again, I'm still not sure (personally) of the need/motivation > given either of the "use two entries" or "use re_path()" options. > Maybe it would be a nice-to-have but I'm not seeing the benefit as > outweighing the complexity (remembering docs, and tests, and related > functionality such as reverse() that would also need updating.) > > (IRL I've rarely needed this pattern. I've used both the options above > without issue) > > So, I'd probably be -1 at this point. > > Kind regards > Carlton > > > On Sun, 2 Oct 2022 at 08:16, Meiyer <interd...@gmail.com> wrote: > >> Is there any interest in implementing this feature? If yes, what would be >> the syntax for the path components that would follow the optional parameter >> (only if it is present)? I thought about something along the lines of >> <int:param?:/> with the characters after the second colon having to >> appear literally in the URL. >> For example: >> path(format_lazy('{org}<country_code:country?:/><slug:groupby>/', >> org=pgettext_lazy('URL', 'event/organizers/')), OrganizersView.as_vew()) >> would match both >> /üritus/korraldajad/perekonnanimi/ and >> /üritus/korraldajad/FI/perekonnanimi/ (in Estonian). >> On Monday, September 19, 2022 at 4:07:26 PM UTC+2 matthew.pava wrote: >> >>> I wonder if maybe you should look at the APPEND_SLASH setting. >>> >>> https://docs.djangoproject.com/en/4.1/ref/settings/#append-slash >>> >>> >>> >>> >>> >>> *From:* django-d...@googlegroups.com <django-d...@googlegroups.com> *On >>> Behalf Of *Meiyer >>> *Sent:* Monday, September 19, 2022 8:59 AM >>> *To:* Django developers (Contributions to Django itself) < >>> django-d...@googlegroups.com> >>> *Subject:* Re: Optional URL parameters in django.urls.path >>> >>> >>> >>> > 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-develop...@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 >>> <https://us-east-2.protection.sophos.com?d=google.com&u=aHR0cHM6Ly9ncm91cHMuZ29vZ2xlLmNvbS9kL21zZ2lkL2RqYW5nby1kZXZlbG9wZXJzLzllMDgyOGQ3LTY0MzQtNGZkMS1iNjA1LTgxMTMzNDJmY2JhOW4lNDBnb29nbGVncm91cHMuY29tP3V0bV9tZWRpdW09ZW1haWwmdXRtX3NvdXJjZT1mb290ZXI=&i=NWVjN2YxNzUxNGEyNzMxNmMyMGRkZGU1&t=TTVvYXJ0Y09ia2tXdUJNZlFiWnRBN1BhNExvNWh1d2tTT0poTDR6czhGaz0=&h=9fe189f5c8584ffea3e05d0fa18945a5> >>> . >>> >> -- >> 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/43b40cdf-2f3d-4a28-9208-af16dd68ede0n%40googlegroups.com >> <https://groups.google.com/d/msgid/django-developers/43b40cdf-2f3d-4a28-9208-af16dd68ede0n%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/CAJwKpyQRwLrfhFVLzxMuw3_ycqt0eaDaKHD7habPKPnhRAAJHQ%40mail.gmail.com > <https://groups.google.com/d/msgid/django-developers/CAJwKpyQRwLrfhFVLzxMuw3_ycqt0eaDaKHD7habPKPnhRAAJHQ%40mail.gmail.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/CAMyDDM2bDbimtJ5XuxiTqeb6W-G3yDdkrTeW-8EGKiBKRTGUOg%40mail.gmail.com.