2013-08-07 32 views
0

我有一個名爲Scan,這需要的ModelForm input and其發送到其被假定從Scan視圖獲取input的值,並處理它在另一個視圖Processscan視圖Processscan查看。Django的視圖不獲取後的HttpResponse完全處理()調用

目前,Processscan正從Scan視圖輸入和輸出值,但不會超過該行:

return HttpResponse("We got to the processor with domain: " + EnteredDomain) 

Process看法是這樣的:

def Scan(request): 
    form = SubmitDomain(request.POST or None) # A form bound to the POST data 
    if request.method == 'POST': # If the form has been submitted... 
     if form.is_valid(): # If form input passes initial validation... 
      domainNmCleaned = form.cleaned_data['domainNm'] ## clean data in dictionary 
      form.save() #save cleaned data to the db from dictionary 
      try: 
       return HttpResponseRedirect('/Processscan/?domainNm=' + domainNmCleaned) 
      except: 
       raise ValidationError(('Invalid request'), code='invalid') ## [ TODO ]: add a custom error page here. 
    else: 
     form = SubmitDomain() 

    return render(request, 'VA/index.html', { 
     'form' : form 
    }) 

Processscan視圖看起來像:

def Processscan(request): 
    # mechanize setup 
    harvest = mechanize.Browser() 
    harvest.addheaders = settings.MECHANIZE_USER_AGENT_HARVESTING 

    EnteredDomain = request.GET.get('domainNm') 
    return HttpResponse("We got to the processor with domain: " + EnteredDomain) 

    mechanizeBrowser = mechanize.Browser  
    mechanizeBrowser.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] 

    r=mechanizeBrowser.open('http://www.thedomain.com') 
    output = r.read() 
    print output 

目前,輸出停在這裏,當它應該在Processscan將持續:

return HttpResponse("We got to the processor with domain: " + EnteredDomain) 

任何想法是怎麼回事?

+1

你的意思是它返回「我們到了...」而不是執行其他'Processscan()'? –

+1

您如何期待進程在'return'語句後執行statemetns? – karthikr

+0

@ dan-klasson - 是的。它在返回HttpResponse()時停止並且不繼續進行機械化。任何想法我做錯了什麼? – CodeTalk

回答

1

return HttpResponse之後的任何內容都會被忽略,因爲該行導致視圖返回HttpResponse對象。這是Django用來構造服務器回覆的內容。

只要把這條線。

+0

感謝您的耐心等待 - 我想我已經修好了。非常感謝Dan! – CodeTalk

相關問題