我有一個名爲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)
任何想法是怎麼回事?
你的意思是它返回「我們到了...」而不是執行其他'Processscan()'? –
您如何期待進程在'return'語句後執行statemetns? – karthikr
@ dan-klasson - 是的。它在返回HttpResponse()時停止並且不繼續進行機械化。任何想法我做錯了什麼? – CodeTalk