如何在url模式中传递可选参数(非随机)?
/新/
/新的/保存并添加新/
url(
regex=r'^~new/[save-and-add-new]/$',
view=views.BudgetCreateView.as_view(),
name='create'
),
我需要在:
中使用它def get_success_url(self):
if save_and_add_new_argument_in_url:
return HttpResponseRedirect(reverse('item:new'))
return HttpResponseRedirect(reverse('item:list'))
答案 0 :(得分: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'
),
然后
def get_success_url(self, param=None):
if param is not None:
return HttpResponseRedirect(reverse('item:new'))
return HttpResponseRedirect(reverse('item:list'))