2021.09.03 00:00

When I heard of CGI-Bin I think of early 2000s. I never actually know how it worked. But I just found out today that it’s quite simple and even works with python. Basically it will show on the web app, whatever is printed out from the script. That’s quite neat!

Save this file in cgi-bin/test.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

a = "CGI-Bin"

print("Content-type: text/html\n") # This line is required to show the html content
print("<html>")
print("<h1>{}</h1>".format(a))
print("</html>")

Make the script executable and launch the server using

`chmod +x cgi-bin/test.py
python -m http.server --cgi 8000

Open the web browser and access it from http://localhost:8000/cgi-bin/test.py.



blog comments powered by Disqus