DJANGO:多步骤形式的重定向

发布于 2024-11-09 06:06:33 字数 1752 浏览 0 评论 0原文

我正在尝试使用模型类创建多步骤表单:

我的视图:

# 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

当梦初醒 2024-11-16 06:06:33

从您的代码中我看到,在三个条件下调用 return HttpResponseRedirect(reverse('tx_create'))

  1. DashboardProfile.DoesNotExist 必须引发
  2. 请求方法必须采用“POST”
  3. 形式必须有效

只需确保所有三个条件都满足。在每种情况下使用一些调试输出来查看流程中断的位置。

From your code I see that return HttpResponseRedirect(reverse('tx_create')) is called on three conditions:

  1. DashboardProfile.DoesNotExist must be raised
  2. Request method must by "POST"
  3. form must be valid

Just make sure that all three conditions are met. Use some debugging output in each of these conditions to see where the flow breaks.

满栀 2024-11-16 06:06:33

您在哪里设置session['created_info']

if 'created_info' not in request.session...

另外,您在哪里使用 request.session['created_busi']

Where do you set session['created_info']?

if 'created_info' not in request.session...

Also, where do you use request.session['created_busi']?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文