'的QueryDict'对象没有属性' GET'

时间:2014-12-29 22:41:17

标签: django request

我有这样的要求

Request URL:    http://A.B.C.18:8010/pbx/directory/?hostname=msk-m9-sip232.db.ru&section=directory&tag_name=domain&key_name=name&key_value=test1.db.ru&Event-Name=REQUEST_PARAMS&Core-UUID=96bec236-d834-4c19-971d-d9a5c7aafd58&FreeSWITCH-Hostname=msk-m9-sip232.db.ru&FreeSWITCH-Switchname=msk-m9-sip232.db.ru&FreeSWITCH-IPv4=A.B.C.232&FreeSWITCH-IPv6=%3A%3A1&Event-Date-Local=2014-12-30%2001%3A35%3A09&Event-Date-GMT=Mon,%2029%20Dec%202014%2021%3A35%3A09%20GMT&Event-Date-Timestamp=1419888909111423&Event-Calling-File=sofia_reg.c&Event-Calling-Function=sofia_reg_parse_auth&Event-Calling-Line-Number=2481&Event-Sequence=3594&action=sip_auth&sip_profile=internal&sip_user_agent=Bria%204%204.1%2073903-085cc850-M&sip_auth_username=10001&sip_auth_realm=test1.db.ru&sip_auth_nonce=a7a0ed08-8839-4925-83e9-665bdb0ad7fe&sip_auth_uri=sip%3Atest1.db.ru&sip_contact_user=10001&sip_contact_host=X.Z.A.137&sip_to_user=10001&sip_to_host=test1.db.ru&sip_via_protocol=udp&sip_from_user=10001&sip_from_host=test1.db.ru&sip_call_id=MWRjMTAyZjdiMTQ4OGZmMTIyOWRiMjc1NzI2M2MxNDY&sip_request_host=test1.db.ru&sip_auth_qop=auth&sip_auth_cnonce=dc542a5c5e9d34f7ed48a58bb6f3a9c3&sip_auth_nc=00000001&sip_auth_response=3419868ab9af9e4e5585cbaabba08f0b&sip_auth_method=REGISTER&key=id&user=10001&domain=test1.db.ru&ip=X.Z.A.137

并看到此错误

Exception Value:    
'QueryDict' object has no attribute 'GET'

on

data = request.GET

如果我将请求更改为

Request URL:    http://A.B.C.18:8010/pbx/directory/?hostname=msk-m9-sip232.db.ru&section=directory&tag_name=domain&key_name=name&key_value=test1.db.ru&Event-Name=REQUEST_PARAMS&Core-UUID=96bec236-d834-4c19-971d-d9a5c7aafd58&FreeSWITCH-Hostname=msk-m9-sip232.db.ru&FreeSWITCH-Switchname=msk-m9-sip232.db.ru&FreeSWITCH-IPv4=A.B.C.232&FreeSWITCH-IPv6=%3A%3A1&Event-Date-Local=2014-12-30%2001%3A35%3A09&Event-Date-GMT=Mon,%2029%20Dec%202014%2021%3A35%3A09%20GMT&Event-Date-Timestamp=1419888909111423&Event-Calling-File=sofia_reg.c&Event-Calling-Function=sofia_reg_parse_auth&Event-Calling-Line-Number=2481&Event-Sequence=3594&action1=sip_auth&sip_profile=internal&sip_user_agent=Bria%204%204.1%2073903-085cc850-M&sip_auth_username=10001&sip_auth_realm=test1.db.ru&sip_auth_nonce=a7a0ed08-8839-4925-83e9-665bdb0ad7fe&sip_auth_uri=sip%3Atest1.db.ru&sip_contact_user=10001&sip_contact_host=X.Z.A.137&sip_to_user=10001&sip_to_host=test1.db.ru&sip_via_protocol=udp&sip_from_user=10001&sip_from_host=test1.db.ru&sip_call_id=MWRjMTAyZjdiMTQ4OGZmMTIyOWRiMjc1NzI2M2MxNDY&sip_request_host=test1.db.ru&sip_auth_qop=auth&sip_auth_cnonce=dc542a5c5e9d34f7ed48a58bb6f3a9c3&sip_auth_nc=00000001&sip_auth_response=3419868ab9af9e4e5585cbaabba08f0b&sip_auth_method=REGISTER&key=id&user=10001&domain=test1.db.ru&ip=X.Z.A.137

一切都很好!

我只更改了一个参数

action to action1

urls.py

from django.conf.urls import patterns, url
from face import views as fv
from pbx import views as pv
urlpatterns = patterns('',
    url(r'directory/$', pv.get_user_info,),
)

views.py

from django.shortcuts import render
from django.db.models import Q
from face import models as fm
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render_to_response, get_object_or_404
from django.http import Http404
from django.http import HttpResponse
import json, datetime
from django.utils.html import escape

...

def get_all_domains(location):

    location = get_object_or_404(fm.PBXServerLocation, name=location)
    domains = fm.PBXDomain.objects.filter(location=location).filter(Q(status=1) | Q(status=2))

    return render_to_response('section_directory.xml', {'domains': domains})


def get_user_info(data):
    location = get_object_or_404(fm.PBXServerLocation, name=data.get('hostname', default=None))
    domains = fm.PBXDomain.objects.filter(location=location).filter(Q(status=1) | Q(status=2))
    domain = data.get('domain', default=None)
    if domain is not None and domain in domains:
        domain = get_object_or_404(fm.PBXDomain, name=domain)
        user = fm.PBXUser.objects.filter(user_id=data.get('user', default=None), pbx_domain=domain)
        return render_to_response('section_directory_user.xml', {'user': user})
    else:
        raise Http404

@csrf_exempt
def get_user_info(request):

    if request.method == "GET":
        data = request.GET
    else:
        data = request.POST

    # list_users
    if data.get('section', default=None) == "directory" and \
                    data.get('tag_name', default=None) == "" and \
                    data.get('key_name', default=None) == "" and \
                    data.get('key_value', default=None) == "":
        return get_all_domains(data.get('hostname', default=None))

    # user register from endpoint
    elif data.get('section', default=None) == "directory" and \
                    data.get('action', default=None) == "sip_auth":
        get_user_info(data)

    else:

        domain = get_object_or_404(fm.PBXDomain, name=data.get('domain'))
        user = get_object_or_404(fm.PBXUser, user_id=data.get('user'), pbx_domain=domain)
        return render_to_response('user.xml', {'user': user, 'data': data})

错误:

AttributeError at /pbx/directory/
'QueryDict' object has no attribute 'method'

./pbx/views.py in get_user_info
if request.method == "GET":

UPDATE2: 我减少了请求

AttributeError at /pbx/directory/
'QueryDict' object has no attribute 'method'
Request Method: GET
Request URL:    http://37.18.2.18:8010/pbx/directory/?section=directory&action=sip_auth
Django Version: 1.7.1
Exception Type: AttributeError
Exception Value:    
'QueryDict' object has no attribute 'method'
Exception Location: ./pbx/views.py in get_user_info, line 47
Python Executable:  /usr/local/bin/uwsgi

1 个答案:

答案 0 :(得分:0)

您有两个名为get_user_info的函数。第二个是视图,它会覆盖第一个。

因此,当您的视图尝试调用该函数时,它实际调用的是它本身。

将独立小说重命名为其他内容。