Jak wykonać skrypt Pythona na BaseHTTPSERVER utworzonym przez Pythona?
Po prostu stworzyłem serwer Pythona z:
python -m SimpleHTTPServer
Miałem .htaccess (nie wiem, czy jest to przydatne z serwerem Pythona) z:
AddHandler cgi-script .py
Options +ExecCGI
Teraz piszę prosty skrypt Pythona:
#!/usr/bin/python
import cgitb
cgitb.enable()
print 'Content-type: text/html'
print '''
<html>
<head>
<title>My website</title>
</head>
<body>
<p>Here I am</p>
</body>
</html>
'''
Robię test.py (nazwa mojego skryptu) wykonanym plikiem z:
chmod +x test.py
Uruchamiam w firefox z tym adresem: (http: //) 0.0.0.0:8000/test.py
Problem, skrypt nie jest wykonywany ... Widzę kod na stronie internetowej ... A błąd serwera to:
localhost - - [25/Oct/2012 10:47:12] "GET / HTTP/1.1" 200 -
localhost - - [25/Oct/2012 10:47:13] code 404, message File not found
localhost - - [25/Oct/2012 10:47:13] "GET /favicon.ico HTTP/1.1" 404 -
Jak mogę po prostu zarządzać wykonaniem kodu Pythona? Czy można napisać na serwerze Pythona, aby wykonać skrypt Pythona tak, jak w przypadku czegoś takiego:
import BaseHTTPServer
import CGIHTTPServer
httpd = BaseHTTPServer.HTTPServer(\
('localhost', 8123), \
CGIHTTPServer.CGIHTTPRequestHandler)
### here some code to say, hey please execute python script on the webserver... ;-)
httpd.serve_forever()
Albo coś innego...