尝试创建将以下引导程序形式转换为Django形式的方法 https://codepen.io/designify-me/pen/qrJWpG?editors=1010使用一个视图
我已经完成了获取数据并将其保存到django会话中的第一个部分。如何在不使用js或ajax的情况下重定向到第二部分
if rf.is_valid():
logger.debug("the form is valid ")
email = rf.cleaned_data.get("email")
first = rf.cleaned_data.get("first_name")
last = rf.cleaned_data.get("last_name")
password = rf.cleaned_data.get("password")
phone = rf.cleaned_data.get("phone")
logger.info("trying to register")
try:
user = User.objects.create_user(email, password, phone, first)
user.username = user.email
#user.first_name = first
user.last_name = last
#user.phone = phone
if original_referrer:
user.original_referrer = original_referrer
request.session['user_details'] = {
"email": rf.cleaned_data["email"],
"first": rf.cleaned_data["first_name"],
"last": rf.cleaned_data["last_name"],
"password": rf.cleaned_data["password"],
"phone": rf.cleaned_data["phone"],
}
logger.debug(request.session['user_details'])
is_successed=1
答案 0 :(得分:0)
我假设由于您已将数据保存到会话中,因此您想要重定向到另一个视图并访问该会话数据。您可以这样做
from django.http.response import HttpResponseRedirect
if rf.is_valid():
...
# Replace with your url or use the reverse function for a named url
return HttpResponseRedirect('/the/next/view/')
然后在下一个视图中
def step2_view(request):
user_details = request.session['user_details']
您也可以查看django-formtools库中的向导表单,这些表单使imo https://django-formtools.readthedocs.io/en/latest/wizard.html
变得更容易一些