2011-05-23 50 views
2

我試圖使用模型類來創建一個多步的形式: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創建 然而,tx_create似乎永遠不會出現......我該怎麼做/可能是什麼錯誤?

回答

0

從你的代碼,我看到return HttpResponseRedirect(reverse('tx_create'))被稱爲三個條件:

  1. DashboardProfile.DoesNotExist必須提高
  2. 請求方法必須通過 「POST」
  3. 形式必須是有效的

只要確保滿足所有三個條件。在這些條件的每一箇中使用一些調試輸出來查看流程中斷的位置。

+0

「使用一些調試輸出」你是什麼意思? – ellieinphilly 2011-05-23 04:08:58

+0

只需在代碼中插入一些'print「東西」'語句,看它是否打印到控制檯。在'except'和'if'語句後面插入這些'print'。 – 2011-05-23 04:12:01

+0

有沒有更好的方法來執行條件?在另一種方式去了解代碼? – ellieinphilly 2011-05-23 09:59:54

0

你在哪裏設置session['created_info']

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

而且,當你用request.session['created_busi']