1👍
- use the $ajax() function from jquery
- use urllib and urllib2 to access external resources from python. Call these libraries from within your view function
Here’s an example for the $ajax function:
$.ajax({
type: "GET",
url: '/htmlApi/sendSms/',
data: {
'phone':'+12412354135',
},
success: function(data){
$("#ajaxDestination").html(data);
}
});
here’s an example of a view function that posts data to the remote server:
def verify1(request):
u = request.session['user']
u.phone_number = request.GET['phone']
u.save()
apiUrl = "http://www.XXXXXXXXX.net/api/send.aspx?username=XXXXXXX&password=XXXXXX&language=1&sender=XXXXXX&mobile=" + request.GET['phone'] + "&message=" + 'ghis' + " is your verification code."
x = urllib2.urlopen(apiUrl).read()
return HttpResponse(x)
(This is an automated sms sending api call)
Source:stackexchange.com