在HttpResponse()调用之后,Django View没有被完全处理

时间:2013-08-07 17:45:41

标签: python django mechanize httpresponse

我有一个名为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)

知道出了什么问题吗?

1 个答案:

答案 0 :(得分:1)

return HttpResponse被忽略之后的任何内容,因为该行导致视图返回HttpResponse个对象。这是Django用来构建服务器回复的内容。

请把这条线拿走。