我有以下网址
url(r'^signup/','social.views.signup'),
url(r'^submit_signup/','social.views.submit_signup'),
url(r'^signup_complete/','social.views.signup_complete'),
我可以创建一个基于网址选择视图的网址吗?像:
url(r'*/', 'social.views.*')
以便对/ signup的请求将路由到'social.views.signup'
答案 0 :(得分:2)
以某种方式喜欢这个
def test(*args,**kwargs):
view_name = kwargs.pop('view')
view = getattr(social.views,view_name)
return view(*args, **kwargs)
urlpatterns = patterns('',
url(r'^test/(?P<view>.*)$', test),
...
)
或者像这样
VIEWS_LIST = ['signup','submit_signup','signup_complete']
urlpatterns = patterns('social.views',
*[url('%s/' % view,view) for view in VIEWS_LIST]
)
答案 1 :(得分:0)
如果您想进行多个步骤的注册过程,那么您可以使用Django表单向导。这样,您无需为每个注册步骤更改URL。 URL将如下所示:
url(r'^signup/$', SignupWizard([SignupForm_1, SignupForm_2, SignupFormComplete]) ),
查看form wizard文档。