Django错误:未定义全局名称“请求”

时间:2017-06-07 08:01:33

标签: django django-request

我的Django视图遇到了一些问题。我有一个函数Identity_FewUpdates,我收到此错误:global name 'request' is not defined

这很奇怪,因为我有一个看起来非常相似的其他功能,到目前为止我都没有遇到问题。

我的功能如下:

import requests, os, json, glob
from django.shortcuts import render, reverse, get_object_or_404, render_to_response
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, HttpResponse
from models import Person, CountryField
from BirthCertificate.models import BirthCertificate
from forms import PersonForm, PersonForm2
from django.views.generic.edit import UpdateView
from django.template.loader import get_template
from django.template import Context
from xhtml2pdf import pisa

import Logger, Search, Folds, Docs, Buffer, EnterSearch

from chartit import DataPool, Chart

from django.db.models import Count
from django_countries import countries

import time
from random import randint
from django.contrib import messages 

import Global_variables

@login_required
def Identity_FewUpdates(requests):

    query_social_number = request.GET.get('social_number')

    if query_social_number :
        query_social_number_list = Person.objects.filter(social_number__icontains=query_social_number)   
        print query_social_number_list 
    else :
        query_social_number_list = Person.objects.none() # == []


    form = PersonForm(request.POST or None, instance = query_social_number_list.first())

    query_job = request.GET.get('job')

    context = {
        "query_social_number" : query_social_number,
        "query_social_number_list" : query_social_number_list,
        "query_job" : query_job,
        "form": form
    }
    return render(request, "Update.html", context)

该功能暂时是草稿。 你对这个问题有任何想法吗?

1 个答案:

答案 0 :(得分:4)

Django视图函数使request参数不是requests

@login_required
def Identity_FewUpdates(request):

    query_social_number = request.GET.get('social_number')