In Django urls, I need an extra named group. This conf with no arguments raised exception 404:
r'^list_cv/(?P<category>[\d]+)?/$'
How to make an optional named group?
To be true, it works like this:
r'^list_cv/(?:(?P<category>[\w+])/)?$'
I find it more legible to create a separate url pattern for a URL without a named group.
url(r'^list_cv/$', my_view), url(r'^list_cv/(?P<category>[\d]+)/$', my_view),
The last slash must be part of an optional RE, and RE must be like
r'^list_cv/(?:(?P<category>[\w+])?/)$'
I have not tested this.
Source: https://habr.com/ru/post/902397/More articles:Access iPhone Embedded Ringtones - iosRegexp does not work for special special characters in Perl - regexLanguage Definition - pythonIs PHP a good log library? - phpWhen focusing on an input field with a border of 3px, all other input fields keep moving - htmlHow to make memset with Python buffer object? - pythonDB2 Drop table, if equivalent - sqlProgrammatic access to arbitrary web.config - cannot access appSettings (app.config is ok) - c #Unable to upgrade from Xcode 4.2 to 4.2.1 - xcodeHow to enable "Detected multiple build versions with a GUID" when converting a project from VS 2008 to VS 2010 - c #All Articles