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


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'[d()- +]+$', number):
   return str(resp)

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

Whenever I am requesting getting following error:

Request Method:     GET
Request URL:
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:


Request Method: GET
Request URL:

Django Version: 1.6.2
Python Version: 2.7.5
Installed Applications:
 Installed Middleware:

I have just started to learn Django.

Asked By: user3485393



Django views must always return an HttpResponse object, so try wrapping that string in an HttpResponse:

from django.http import HttpResponse
return HttpResponse(str(resp))

Additionally, the number variable in generate_xml will contain only the string 'number', not the GET parameter. To get that, you might use:

Answered By: DavidM

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)
Answered By: Prashant Gaur