Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create the first CGI program using Python

Shulou Source: shulou.com Published: 2022-06-01 01:33:24 09月15日 Update

In this article Xiaobian for you to introduce in detail "how to use Python to create the first CGI program", the content is detailed, the steps are clear, the details are handled properly, I hope this "how to use Python to create the first CGI program" article can help you solve your doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.

The first CGI program

We use Python to create the first CGI program, the file name is hello.py, and the file is located in the / var/www/cgi-bin directory, as follows:

#! / usr/bin/python3

Print ("Content-type:text/html")

Print () # blank line, telling the server to end the header

Print ('')

Print ('')

Print ('')

Print ('Hello Word-my first CGI program!')

Print ('')

Print ('')

Print ('Hello Word! I am the first CGI program from the rookie tutorial')

Print ('')

Print ('')

Modify the hello.py after the file is saved, and modify the file permission to 755:

Chmod 755 hello.py

The results of the above programs are displayed in the browser as follows:

The hello.py script for this is a simple Python script in which the output of the first line of the script "Content-type:text/html" is sent to the browser and tells the browser that the type of content displayed is "text/html".

Use print to output a blank line to tell the server the end header information.

Read here, this "how to use Python to create the first CGI program" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, welcome to follow the industry information channel.

Tags: Programs content files articles browsers scripts browsing headers servers blank lines services output proper one line information ideas tutorials new knowledge more permissions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno MariaDB Xiaomi Shulou Information