2016-08-09 22 views
0

Kann jemand darauf hinweisen, wo ich hier falsch liege. Ich habe zwei Skripte, eines für das Formular und das andere für die Verarbeitung. Es sieht richtig aus, aber nach zwei Stunden des Starrens kann ich nicht sehen, wo ich falsch liege. Hier sind die zwei Skripte, sie sind sehr kurz, also schaut es euch bitte an.Verarbeitung von Formulardaten mit einem Python-CGI-Skript

Die Form:

#!/usr/bin/python 
import os 
import cgi 
import cgitb 



print("Content-Type: text/html\n\n") 
print("") 

print'''<html> 
<head> 
<meta charset="utf-8"> 
    <title>Marks Sonitus Practice</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <meta name="description" content="Practice"> 
    <meta name="author" content="CGI Practice"> 
</head> 
<body> 
<form action="process_data.py" method="post"> 
    <html><span> First &nbsp;&nbsp;&nbsp;</span></label> 
    <input type="text" name="firstname"/> 
    <input type="submit" name ="submitname" value="Submit Name"></form> 
</body> 
</html>''' 

Das Skript, das Formular zu verarbeiten:

#!/usr/bin/python 
import os 
import cgi 
import cgitb 
cgitb.enable(display=0,logdir="/var/www/cgi-bin/error-logs") 

file_name = "/var/www/cgi-bin/practice/process_practice.py" 
f = os.path.abspath(os.path.join(file_name)) 
try: 
    open(f) 
except: 
    print"This file could not be found!" 
form = cgi.FieldStorage(f) 
firstname = form.getvalue('firstname') 
print firstname 

Kann jemand mir zeigen, wo ich mit diesem falschen werde?

+0

Entschuldigung, ich hätte sagen sollen - wenn ich dieses Skript ausführen, druckt es keine. Kein Fehler, nichts in den Fehlerprotokolldateien, nur keine. –

+0

"* Wenn ich dieses Skript ausführen, druckt es keine. *" - Genau, wie läuft das Skript? –

+0

@rob Ich führe es vom Terminal mit Python NameOffile.py –

Antwort

0

Nun das ist einfach in der Form ersetzen die action=process_data.py zu action=http://localhost/cgi-bin/practice/process_practice.py oder sein kann action=http://localhost/cgi-bin/practice/process_data.py, was der Name dieses Skript.

+0

Vielen Dank. Das hat funktioniert. Dumm von mir! –

0

Wechsel aus:

action=process_data.py 

zu:

action=http://localhost/cgi-bin/practice/process_data.py 

Arbeitete.