Bonjour,

Je découvre actuellement CGIHTTPServer qui fontionne bien. Le mini serveur fonctionne en local et je voudrais m'en servir pour tester quelques scripts CGI en python. Je ne parviens pas, hélas, à faire pointer l'url directement sur le fichier index.cgi lorsque je rentre l'url suivante : http://localhost:8000/cgi-bin/

Quelqu'un saurait-il comment faire ? Y a-t-il un moyen d'avoir l'équivalent de fichiers .htaccess qui permettraient cette redirection ?

L'arborescence est la suivante:

.
|-- test.py
`-- www
....|-- cgi-bin
....| ....|-- index.cgi
....`-- index.html



Voici mon code:

.test.py

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
 
import CGIHTTPServer, BaseHTTPServer
import os
 
# Le serveur isole l'exécution du programme automatiquement au repertoire dans lequel il est lancé.
# Un repertoire ./www doit être créé et contiendra une page html vide qui servira pour la redirection vers les scripts cgi.
# Le repertoire ./www doit contenir un autre repertoire ./cgi-bin dans lequel seront placés les scripts cgi.
 
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
	cgi_directories =  ['/cgi-bin']
 
port = 8000
os.chdir('./www')
httpd = BaseHTTPServer.HTTPServer(('', int(port)),Handler)
try:
	print "\nServer is running and listening on Port %s.\nGo to http://localhost:%s\nControl-C to quit.\n---" % (port,port)
	httpd.serve_forever()
except KeyboardInterrupt:
	print ' \nStopping the Server...'

./www/index.html

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Index</title>
<meta http-equiv="REFRESH" content="0;url=/cgi-bin/index.cgi"></HEAD>
<BODY>
 
</BODY>
</HTML>
.www/cgi-bin/index.cgi

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
#!/usr/bin/python
# -*- encoding: utf-8 -*-
 
import cgi
 
print "Content-Type: text/html\n\n"
print
# Là commence le code.
 
print "Hello !"


Merci pour votre aide.