Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 'str' object has no attribute 'get' in Django

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'), 

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-      

Full Traceback:

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') 

I have just started to learn Django.

like image 574
user3485393 Avatar asked Apr 01 '14 13:04

user3485393


1 Answers

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

from django.http import HttpResponse 

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

 return HttpResponse(resp) 
like image 187
Prashant Gaur Avatar answered Sep 23 '22 10:09

Prashant Gaur