DJANGO:多步骤形式的重定向
我正在尝试使用模型类创建多步骤表单:
我的视图:
# this is my tz_create view
def makingx(request):
try:
#this is to check if user has filled info already before
dashprofile = DashboardProfile.objects.get(user=request.user)
#some view stuff
context = {
'user':user
}
return render_to_response(
'done.html',
context,
context_instance = RequestContext(request),
)
except DashboardProfile.DoesNotExist:
#some more stuff
if request.method == "POST":
if form.is_valid():
#more view stuff
request.session['created_busi'] = True
return HttpResponseRedirect(reverse('tx_create'))
else:
return render_to_response(
'd12.html',
{
'user':user},
context_instance = RequestContext(request)
)
我的 tx_create 视图:
def promocamp(request):
if 'created_info' not in request.session:
return HttpResponseRedirect(
reverse('tz_create')
)
user = request.user
if request.method == "POST":
if campaign.is_valid():
#some stuff
if 'next' in request.POST:
next = request.POST['next']
else:
next = reverse('busi_create')
return HttpResponseRedirect(next)
return render_to_response(
'd14.html',
{'CampaignForm':campaign,
'user':user},
context_instance = RequestContext(request)
)
步骤需要从 tz 转到 tx create 然而 tx_create 似乎从未出现...我应该做什么/可能是什么错误?
I am trying to create a multi step form using model classes:
my view:
# this is my tz_create view
def makingx(request):
try:
#this is to check if user has filled info already before
dashprofile = DashboardProfile.objects.get(user=request.user)
#some view stuff
context = {
'user':user
}
return render_to_response(
'done.html',
context,
context_instance = RequestContext(request),
)
except DashboardProfile.DoesNotExist:
#some more stuff
if request.method == "POST":
if form.is_valid():
#more view stuff
request.session['created_busi'] = True
return HttpResponseRedirect(reverse('tx_create'))
else:
return render_to_response(
'd12.html',
{
'user':user},
context_instance = RequestContext(request)
)
my tx_create view:
def promocamp(request):
if 'created_info' not in request.session:
return HttpResponseRedirect(
reverse('tz_create')
)
user = request.user
if request.method == "POST":
if campaign.is_valid():
#some stuff
if 'next' in request.POST:
next = request.POST['next']
else:
next = reverse('busi_create')
return HttpResponseRedirect(next)
return render_to_response(
'd14.html',
{'CampaignForm':campaign,
'user':user},
context_instance = RequestContext(request)
)
Step needs to go from tz to tx create
However tx_create never seems to show up... what should i do / what could be the error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的代码中我看到,在三个条件下调用
return HttpResponseRedirect(reverse('tx_create'))
:只需确保所有三个条件都满足。在每种情况下使用一些调试输出来查看流程中断的位置。
From your code I see that
return HttpResponseRedirect(reverse('tx_create'))
is called on three conditions:Just make sure that all three conditions are met. Use some debugging output in each of these conditions to see where the flow breaks.
您在哪里设置
session['created_info']
?另外,您在哪里使用
request.session['created_busi']
?Where do you set
session['created_info']
?Also, where do you use
request.session['created_busi']
?