0

我有一个名为的视图Scan,它采用模型形式input and将其发送到另一个视图Processscan,该视图应该inputScan视图中获取值并在视图中处理它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)

知道出了什么问题吗?

4

1 回答 1

1

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

把那条线拿出来。

于 2013-08-07T18:03:18.723 回答