execute python scripts from html -
Python shows the browser code instead of running the script.
The HTML code is as follows:
& lt; Html & gt; & Lt; body & gt; & Lt; form enctype = "multipart / form-data" verb = "/ static / savefiles.py" method = "post" & gt; & Lt; P & gt; File: & lt; Input type = "file" name = "file" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Input type = "submit" value = "upload" & gt; & Lt; / P & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt; Python code is as follows:
#! C: \ Python27 \ python.exe #! / Usr / bin / python from google.appengine google.appengine.ext.webapp.util import run_wsgi_app import CGI, OS import cgitb; Import webpacks from cgitb.enable () Try: # Windows requires stdio set for binary mode. Import msvcrt msvcrt.setmode (0, os.O_BINARY) # stdin = 0 msvcrt.setmode (1, os.O_BINARY) Excluding # stdout = 1, ImportError: pass form = cgi.FieldStorage () # A nested field holds the storage instance file fileitem = File ['file'] # If the file had been uploaded, fileitem.filename: # strip to avoid the file path by the main name, open directory traversal attacks fn = os.path.basename (fileitem.filename) (os .path.join ('static / file /' + fn, 'wb')). Write (fileitem.file.read ()) message = 'file' '+ + FN +' was successfully uploaded 'else: message =' no file was uploaded "print" "\ content type: text / html \ n B & gt; & lt; p & gt;% s & lt; / body & gt; & lt; / html & gt; ""% (Message,) I have tried various solutions posted on the forum, but none of them works in my case. Please guide me to who needs to be corrected. Thanks for your quick help.
I just stumbled over this question and I have only one problem. Do you have the answer now?
Why your code is not working, because HTML is not interpreting as a dragon file, as much as I think it is because my problem is yet to be solved. To understand a python file, you need a type of interpreter for HTML.
Comments
Post a Comment