如何在视图中包装Django Form Wizard?我需要这样做才能访问request
。
有没有人为此提供一些示例代码?
答案 0 :(得分:5)
我可能应该只是评论Manoj的答案,但听起来你需要代码
urls.py
from django.conf.urls.defaults import *
from MyApp import views
urlpatterns = patterns(
'',
(r'^wizard/$', views.MyWizardView ),
)
views.py
@login_required
def MyWizardView (request):
cw = MyWizard([WizardName, WizardQuestions, WizardProvider, WizardGoomber])
return cw(request)
答案 1 :(得分:2)
as_view
函数将基于类的视图转换为可调用的视图:
from django import forms
from django.contrib.formtools.wizard.views import SessionWizardView
class Form1(forms.Form):
a = forms.CharField()
class Form2(forms.Form):
b = forms.CharField()
class MyWizard(SessionWizardView):
pass
wizard_view = MyWizard.as_view([Form1, Form2])
def view(request):
# do something fancy with the request object here
return wizard_view(request)
中的答案基本相同
答案 2 :(得分:0)
这Django snippet可能有用。
从标题:“ FormWizard内部视图,具有适当的上下文处理和站点模板支持,无需使用urls.py ”