我有一个名为Scan
的视图,它将模型形式input and
发送到另一个视图Processscan
,该视图应该从{input
获取Scan
的值1}}在Processscan
视图中查看和处理它。
目前,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)
知道出了什么问题吗?
答案 0 :(得分:1)
return HttpResponse
被忽略之后的任何内容,因为该行导致视图返回HttpResponse
个对象。这是Django用来构建服务器回复的内容。
请把这条线拿走。