获取'str'对象在Django中没有属性'get' [英] Getting 'str' object has no attribute 'get' in Django

查看:1709
本文介绍了获取'str'对象在Django中没有属性'get'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在stackoverflow上的第一个问题:

This is my first question here on stackoverflow:

views.py

def generate_xml(request, number):
    caller_id = 'x-x-x-x'
    resp = twilio.twiml.Response()

    with resp.dial(callerId=caller_id) as r:
         if number and re.search('[\d\(\)\- \+]+$', number):
            r.number(number)
         else:
             r.client('test')
   return str(resp)

url.py

url(r'^voice/(?P<number>\w+)$', 'django_calling.views.generate_xml', name='generating TwiML'),

每当我要求 http://127.0.0.1:8000/voice/number?id=98 获取以下错误:

Whenever i am requesting http://127.0.0.1:8000/voice/number?id=98 getting following error:

Request Method:     GET
Request URL:    http://127.0.0.1:8000/voice/number?id=90
Django Version:     1.6.2
Exception Type:     AttributeError
Exception Value:    'str' object has no attribute 'get'

Exception Location:     /usr/local/lib/python2.7/dist-     
enter code here

完整追溯:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/voice/number?id=90

Django Version: 1.6.2
Python Version: 2.7.5
Installed Applications:
 ('django.contrib.admin',
'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_calling',
'django_twilio',
'twilio')
 Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')

我刚刚开始学习 Django ,需要你的帮助才能解决。谢谢!

I have just started to learn Django, Need your help to get solved. Thanks!

推荐答案

您不能直接通过 str 作为 django response
您必须使用

You can not pass directly str as a django response . You must use

from django.http import HttpResponse

如果要将字符串数据呈现为django视图响应。
看看此处

if you want to render string data as django view response. have a look here


return HttpResponse(resp)

这篇关于获取'str'对象在Django中没有属性'get'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆