[Fixed]-Optional(not random) argument in URL patterns

1👍

url(
regex=r'^~new/(?P<param>\w+)/$',
view=views.BudgetCreateView.as_view(),
name='create'
),
url(
regex=r'^~new/$',
view=views.BudgetCreateView.as_view(),
name='create'
),

Then

def get_success_url(self, param=None):
   if param is not None:
       return HttpResponseRedirect(reverse('item:new'))
   return HttpResponseRedirect(reverse('item:list'))

Leave a comment