user2957682
user2957682

Reputation: 189

Twilio django send SMS and get answer using SMS as parameter

In the twilio example made in flask, I can send an SMS and receive an answer using text and the SMS as the search parameter in the database. I need make this but in a django project, my first option that I thought make a django view with a parameter using a url with for send the parameter, but I see that is bad idea because not is possible can use the text of SMS as parameter This is a part of flask example

@app.route('/directory/search', methods=['POST'])
def search():
    query = request.form['Body']

I need make some similar to that view in django using django restframework but how I can get the Body (I think that the body is the text send in the SMS) for use this as parameter

Upvotes: 0

Views: 189

Answers (1)

Aaron Lelevier
Aaron Lelevier

Reputation: 20760

Use request.POST to access the form data:

from django.shortcuts import render

def my_view(request):
    if request.method == "POST":
        data = request.POST
        # all posted data
        data['body']

    # the rest of your view logic

    return render(request, 'template.html', context)

Upvotes: 1

Related Questions