I am trying to execute python script in apache2 server but apache2 server downloads python file instead of executing it. I am sending request to server using xmlhttprequest object in javascript I have given url as filename(test.py) in xmlhttprequest object. Added handler for cgi and mod_python in apache config file but it did not work
#!/usr/bin/python
import cgi
import cgitb
cgitb.enable()
from mod_python import apache
print "hello world"
html code
<!DOCTYPE html>
<html>
<head>
<script>
function runJS() {
var code = Blockly.C.workspaceToCode(Code.workspace);
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","/cgi-bin/process.py",false);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("code=" + encodeURIComponent(code));
alert(xmlhttp.responseText);
}
</script>
</head>
<body>
<button onclick="runJS()">click</button>
</body>
</html>
My apache config file for mod_python
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher | .py
PythonDebug On
</Directory>
for cgi
ScriptAlias "/cgi-bin/" "/var/www/html/cgi-bin/"
<Directory /var/www/html/cgi-bin>
Options ExecCGI Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler cgi-script .py
</Directory>
or suggest any alternate way to execute python script in webserver