0

I have this python code:

from twilio.rest import Client

account_sid = "myID"
auth_token = "myAuth"

client = Client(account_sid, auth_token)

client.api.account.messages.create(
to="+num1",
from_="num2",
body="Hello there!")

and when I execute it on the command line python file.py everything works fine,(aka a text is sent to my phone) but I want to execute this code from a javascript file and I am doing this:

$.ajax({
  type: "GET",
  url: "file.py",
}).done(function( o ) {
   console.error("WOW")
});

but the python is not being executed although I do see the console error. I'm not too sure whats going on, I'm wondering if this needs to be changed to a POST request, but that simply gives me a 404 not found error.

Ore Arowobusoye
  • 147
  • 1
  • 7

1 Answers1

1

I don't think we can give a python filename as url value. AJAX will send a request to the server and in order to handle that request we will need a server side scripting language. Below link explains how to handle AJAX request in Django.

How do I integrate Ajax with Django applications?

Asit Rout
  • 189
  • 2
  • 11