Se si utilizza il proprio computer, installare un software chiamato XAMPP (o funziona anche WAMPP). Questo è fondamentalmente un server web che gira solo sul tuo computer. Quindi, una volta installato, vai alla cartella xampp e fai doppio clic sulla cartella htdocs. Ora quello che devi fare è creare un file html (lo chiamerò runpython.html). (Ricordarsi di spostare il file python per htdocs pure)
Aggiungi in questo per il vostro corpo html (e gli ingressi, se necessario)
<form action = "file_name.py" method = "POST">
<input type = "submit" value = "Run the Program!!!">
</form>
Ora, nel file python, ci sono fondamentalmente andando essere la stampa fuori codice HTML.
#We will need a comment here depending on your server. It is basically telling the server where your python.exe is in order to interpret the language. The server is too lazy to do it itself.
import cgitb
import cgi
cgitb.enable() #This will show any errors on your webpage
inputs = cgi.FieldStorage() #REMEMBER: We do not have inputs, simply a button to run the program. In order to get inputs, give each one a name and call it by inputs['insert_name']
print "Content-type: text/html" #We are using HTML, so we need to tell the server
print #Just do it because it is in the tutorial :P
print "<title> MyPythonWebpage </title>"
print "Whatever you would like to print goes here, preferably in between tags to make it look nice"
questo è python non php, devi configurare python web framework e, g, webpy o django ecc. e configurare appache con mod_python. –
prova whisky !! : D "WSGI" (interfaccia gateway server Web). – Arunmu
È possibile eseguire Python in una pagina Web (sul lato client) utilizzando framework come Pyjamas e Skulpt. –