I just wrote a sample app using Twilio and Django on GitHub, but here's the specific answer you're looking for.
For this example I'm using the '/reply/' URL on my server (and have told Twilio that's where to POST to)
In urls.py you're just going to do a standard mapping:
url(r'^reply', 'twilio_sms.views.sms_reply'),
Here's a really basic response to the user, responding with what the Twilio server expects.
def sms_reply(request):
if request.method == 'POST':
params = request.POST
phone = re.sub('+1','',params['From'])
response_message = '<?xml version="1.0" encoding="UTF-8">'
response_message += '<Response><Sms>Thanks for your text!</Sms></Response>'
return HttpResponse(response_message)
In my code I actually build the XML response using a library, which I suggest in general, but for a code sample it's too much information.