Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a very simple Python file, called python1.py, whose contents are:

f = open('C:\Temp\test.txt', 'w')
f.write('Succeeded')
f.close()

I wish to execute this from JavaScript, like so:

jQuery.ajax({
   type: "POST",
   url: "/cgi-bin/python1.py",
   success: function (msg) {
       alert("Data Saved: " + msg);
   }
});

However, all that happens is that I get an alert showing me the contents of the Python script. The file C:Tempest.txt does not get created, so clearly the Python was not executed.

How do I persuade the code to execute the Python script instead of just reading it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
148 views
Welcome To Ask or Share your Answers For Others

1 Answer

You simply need to configure your web server to execute your *.py scripts, instead of serving them as plain text.

If you are using Apache as a web server, you need to enable mod_python or mod_wsgi.


EDIT:

Since you are using using Apache, you may want to check the following article, which briefly describes how to set up the mod_python module:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...