python:executer_python_chez_ovh

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
python:executer_python_chez_ovh [2020/02/02 09:22] – créée physixpython:executer_python_chez_ovh [2020/07/24 03:31] (Version actuelle) – modification externe 127.0.0.1
Ligne 1: Ligne 1:
 ====== Exécuter Python sur OVH ====== ====== Exécuter Python sur OVH ======
 +
 +===== La base =====
  
 Mettre le fichier .cgi dans /cgi-bin/ Mettre le fichier .cgi dans /cgi-bin/
  
-#!/usr/bin/python+{{:python:c9ccc31a58f5ff99c80d75216fb0976b.png}}
  
 +Passer le fichier en exécutable (705)
 +
 +{{:python:b2d8d9410aad47d8d60f63139ec248ec.png}}
 +
 +Contenu du fichier :
 +
 +<code>
 +#!/usr/bin/python
 # -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
 +print("Content-type: text/html\n\n")
 +print("Hello World!")
  
 +</code>
 +
 +Ou
 +
 +<code>
 +#!/usr/bin/python
 +# -*- coding: UTF-8 -*-
 print("Content-type: text/html\n\n") print("Content-type: text/html\n\n")
 +from random import *
  
-print("Hello World!")+for i in range (1,10): 
 +    print (random()) 
 + 
 +</code> 
 + 
 +Pour afficher : 
 + 
 +[[http://physix.fr/cgi-bin/test.cgi|http://physix.fr/cgi-bin/test.cgi]] 
 + 
 +===== Pour afficher les erreurs =====<code> 
 + 
 +import cgitb 
 +cgitb.enable() 
 + 
 +</code> 
 + 
 + 
 +===== Compteur de visite ===== 
 + 
 +<code> 
 +#!/usr/bin/python 
 +from datetime import datetime 
 +import cgitb 
 +cgitb.enable() 
 + 
 +print 'Content-type: text/html' 
 +print 
 +print (datetime.now()) 
 + 
 +try: 
 +    fichier = open('compteur','r'
 +    nbr_visiteurs = int(fichier.read()) 
 +except Exception: 
 +    nbr_visiteurs = 0 
 +fichier = open('compteur','w'
 +fichier.write(str(nbr_visiteurs+1)) 
 +print nbr_visiteurs+1,'visites \o/' 
 + 
 +</code> 
 +===== Liens ===== 
 + 
 +[[https://fr.wikibooks.org/wiki/Programmation_Python/L'interface_CGI|https://fr.wikibooks.org/wiki/Programmation_Python/L'interface_CGI]] 
 + 
 +[[http://sdz.tdct.org/sdz/apercu-de-la-cgi-avec-python.html|http://sdz.tdct.org/sdz/apercu-de-la-cgi-avec-python.html]]
  
  
  • python/executer_python_chez_ovh.1580631734.txt.gz
  • Dernière modification : 2020/07/24 00:23
  • (modification externe)