我正在尝试为django-userena注册设置多个表单。
所以从django-docs我可以这样做:
表格.py:
class Form1(forms.Form):
some_field = forms.CharField(max_length=100)
email = forms.EmailField()
class Form2(forms.Form):
some_field_2 = forms.CharField(widget=forms.Textarea)
视图.py:
class Wizard(SessionWizardView):
def done(self, form_list, **kwargs):
return render_to_response('done.html', {
'form_data': [form.cleaned_data for form in form_list],
})
网址.py:
(r'^signup/$', Wizard.as_view([Form1, Form2])),
它就像一个表单,放在两个页面上,带有“下一个”和“上一个”按钮。
但是userena代码有一些不同,应该是这样的:
视图.py:
if userena_settings.USERENA_WITHOUT_USERNAMES and (signup_form == SignupForm):
signup_form = SignupFormOnlyEmail
form = signup_form()
if request.method == 'POST':
form = signup_form(request.POST, request.FILES)
if form.is_valid():
user = form.save()
# Send the signup complete signal
userena_signals.signup_complete.send(sender=None,
user=user)
if success_url: redirect_to = success_url
else: redirect_to = reverse('userena_signup_complete',
kwargs={'username': user.username})
# A new signed user should logout the old one.
if request.user.is_authenticated():
logout(request)
return redirect(redirect_to)
if not extra_context: extra_context = dict()
extra_context['form'] = form
return ExtraContextTemplateView.as_view(template_name=template_name,
extra_context=extra_context)(request)
网址.py:
url(r'^accounts/signup/$', 'userena.views.signup', {'signup_form': SignupFormExtra}),
所以我的大问题在这里 - 整合这两件事,但我什至不知道我应该从什么开始。