Django URL 配置
我有一个购买页面,它可以采用可选参数作为礼物,如果是礼物,则视图将礼物表单传递给模板,如果不是,则传递常规购买表单。
我的旧常规网址,它重定向到两个单独的视图:
(r'^(?P<item>[-\w]+)/purchase/$', 'purchase_view'),
(r'^(?P<item>[-\w]+)/purchase/gift$', 'gift_view'),
视图是这样的:
def purchase_view(request,item):
....use purchase form
def gift_view(request,item):
....use giftform
这确实是一个糟糕的设计,因为两个视图几乎所有内容都相同,但所使用的表单不同。
我也考虑过使用 GET 并将礼物作为 GET 参数,但这不是一个好主意,因为我对这些页面使用 POST 方法,尤其是在验证后会导致问题。
我怎样才能使它成为一个单一的网址和一个单一的视图?
谢谢
I have a purchase page, it can take an optional argument as a gift, if it is a gift, the view passes a gift form to the template and if not, a regular purchase form.
my old regular url, which redirects to two seperate views:
(r'^(?P<item>[-\w]+)/purchase/
and the views was like this:
def purchase_view(request,item):
....use purchase form
def gift_view(request,item):
....use giftform
It is a bad design indeed, as both views having are almost everything same but the forms used.
I have also thougt about using GET and giving gift as a GET param however it wasnt a good idea as I am using POST method for these pages, especially would cause issue after validation.
How can I make this a single url and a single view?
Thanks
, 'purchase_view'),
(r'^(?P<item>[-\w]+)/purchase/gift
and the views was like this:
It is a bad design indeed, as both views having are almost everything same but the forms used.
I have also thougt about using GET and giving gift as a GET param however it wasnt a good idea as I am using POST method for these pages, especially would cause issue after validation.
How can I make this a single url and a single view?
Thanks
, 'gift_view'),
and the views was like this:
It is a bad design indeed, as both views having are almost everything same but the forms used.
I have also thougt about using GET and giving gift as a GET param however it wasnt a good idea as I am using POST method for these pages, especially would cause issue after validation.
How can I make this a single url and a single view?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
urls.py
views.py
urls.py
views.py