﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35403	URL path with optional parameter	Patrick Hintermayer	nobody	"I sometimes have a class based view which has a GET and a POST method, for example a ListView which shows some objects with a POST form to create something out of it.

In the documentation (https://docs.djangoproject.com/en/5.0/topics/http/urls/) I did not find a simple way of doing that. Asking GitHub Copilot suggested me adding a question mark at the end to mark a parameter as optional which does not work.

**I found myself 2 solutions:**
1. using regex which looks cumbersome just for marking something as optional:
{{{#!div style=""font-size: 80%""
Code highlighting:
  {{{#!python
  re_path(
        r""^activate/(?P<activation_token>[^/]+)?$"",
        views.UserActivationView.as_view(),
        name=""user_activation"",
    )
  }}}
}}}
 
2. using 2 paths: one without a parameter and one with a parameter:
{{{#!div style=""font-size: 80%""
Code highlighting:
  {{{#!python
  path(
        ""activate/"",
        views.UserActivationView.as_view(),
        name=""user_activation"",
    ),
    path(
        ""activate/<str:activation_token>/"",
        views.UserActivationView.as_view(),
        name=""user_activation"",
    )
  }}}
}}}
  
For this ticket, I want to suggest a) improve the documentation with a simple example how to do that and/or b) can this be simplified in django by adding for example a question mark at the end like ""/<int:some_id?>/"" or  ""/<int?:some_id>/"":
{{{#!div style=""font-size: 80%""
Code highlighting:
  {{{#!python
  path(
        ""activate/<str:activation_token?>/"",
        views.UserActivationView.as_view(),
        name=""user_activation"",
    )
  }}}
}}} "	Uncategorized	closed	Uncategorized	5.0	Normal	invalid	url		Unreviewed	0	0	0	0	0	0
