Z
Z
zergon3212016-10-31 10:03:43
Python
zergon321, 2016-10-31 10:03:43

Why is the source code of the cgi script, when requested, displayed in the browser, but the script itself does not display html markup?

I did everything like here: https://pythonworld.ru/web/cgi-1.html
Script code:

print("Content-type: text/html")
print()
print(
"""<html>
<body>
<h1>GOTO HELL</h1>
</body>
</html>""")

Windows 10 OS, the server is working fine.
Server code:
from http.server import HTTPServer, CGIHTTPRequestHandler
server_address = ("localhost", 8000)
httpd = HTTPServer(server_address, CGIHTTPRequestHandler)
httpd.serve_forever()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2016-10-31
@saboteur_kiev

The script needs to be handled. That is, the web server must understand that this is a script and execute it, and not display it as a page.
Make sure scripts are allowed in your folder

<Directory "/var/www/htdocs/somedir">
    Options +ExecCGI
</Directory>

Make sure the file extension is specified in the AddHandler
handler cgi-script .cgi .pl
You can even specify a handler specifically for this folder:
<Directory "/home/*/public_html">
    Options +ExecCGI
    AddHandler cgi-script .cgi
</Directory>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question