Getting str object has no attribute get in Django

2024/11/18 21:27:51

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=90Django 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.

Answer

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)
https://en.xdnf.cn/q/26515.html

Related Q&A

Cython Speed Boost vs. Usability [closed]

Closed. This question is opinion-based. It is not currently accepting answers.Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.Clo…

cc1plus: warning: command line option -Wstrict-prototypes is valid for Ada/C/ObjC but not for C++

I am building a C++ extension for use in Python. I am seeing this warning being generated during the compilation process - when a type:python setup.py build_ext -iWhat is causing it, and how do I fix i…

Any way to add a new line from a string with the \n character in flask?

I was playing around with flask when I came across an odd problem with the \n character. it dosent seem to have an effect in my browser, I tried putting in there but it didnt work, any ideas?from fla…

Get list of Cache Keys in Django

Im trying to understand how Django is setting keys for my views. Im wondering if theres a way to just get all the saved keys from Memcached. something like a cache.all() or something. Ive been trying t…

numpy: multiply arrays rowwise

I have those arrays:a = np.array([[1,2],[3,4],[5,6],[7,8]])b = np.array([1,2,3,4])and I want them to multiply like so:[[1*1, 2*1], [3*2, 4*2], [5*3, 6*3], [7*4, 8*4]]... basically out[i] = a[i] * b[i],…

django post_save signals on update

I am trying to set up some post_save receivers similar to the following: @receiver(post_save, sender=Game, dispatch_uid=game_updated) def game_updated(sender, **kwargs):DO SOME STUFF HEREMyPick.objects…

Fastest way to pack a list of floats into bytes in python

I have a list of say 100k floats and I want to convert it into a bytes buffer.buf = bytes() for val in floatList:buf += struct.pack(f, val) return bufThis is quite slow. How can I make it faster using …

PyPI is slow. How do I run my own server?

When a new developer joins the team, or Jenkins runs a complete build, I need to create a fresh virtualenv. I often find that setting up a virtualenv with Pip and a large number (more than 10) of requi…

How to suppress the deprecation warnings in Django?

Every time Im using the django-admin command — even on TAB–completion — it throws a RemovedInDjango19Warning (and a lot more if I use the test command). How can I suppress those warnings?Im using D…

whats the fastest way to find eigenvalues/vectors in python?

Currently im using numpy which does the job. But, as im dealing with matrices with several thousands of rows/columns and later this figure will go up to tens of thousands, i was wondering if there was …