0
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
    })

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

请对我放轻松-我还在学习:)

我现在在使用 POST 时遇到 GET 问题,在我最初请求域名时 - 我得到:

'WSGIRequest' object has no attribute 'get'

在:

EnteredDomain = request.get('domainNm', '')
4

1 回答 1

1

您可以直接调用 scanprocess 或简单地通过 GET 传递它:

if form.is_valid(): # If form input passes initial validation...
    domainNm = form.cleaned_data['domainNm']  ## clean data in dictionary
    form.save() #save cleaned data to the db from dictionary

    try:
        return HttpResponseRedirect('/Scanprocess/?domainNm=' + domainNm)
    except:
        raise ValidationError(_('Invalid domain name'), code='invalid')

然后在你看来,你可以通过request.GET.get('domainNm', '')

据我所知,您所需要的urls.py只是:

url(r'^Scanprocess/$', name_of_view),
于 2013-08-07T02:24:18.680 回答