CGI script

Simple example

1) Webpage calling a CGI-script




<title>Python CGI test</title>



<a href="cgi-bin/python_example.cgi">Start CGI script</a>



adapt the path of your server CGI directory

2) Simple Python CGI script file



print('Content-Type: text/html') # HTML is following

print('') # require blank line between CGI header and data

# content

print('<b>Hello World</b>')

a) copy script into the CGI directory on the webserver, the CGI directory can look like:


b) make sure your script is readable and executable by the Web server, give permissions to execute the CGI script by:

chmod a+x python_example.cgi

c) test your script on the server


Content-Type: text/html

<b>Hello World</b>

d) test pure CGI script in web browser

e) finally, copy and test the above webpage which internally calls the CGI script