Python-CGI-WebApp is a simple web application that uses Python 3 scripts to generate dynamic webpages.
A CGI (Common Gateway Interface) enabled HTTP server (written in Python 3) handles these requests.
The Common Gateway Interface offers a standard protocol for web servers to execute programs that execute like Console applications running on a server that generates web pages dynamically.
There are three Python Scripts that work together to generate the HTML webpage
-
generate.py
The Home Page has a link to this python script to start the Web Application. The script imports "keyreader.py" and "template_engine.py" modules and makes function calls to generate the webpage.
-
keyreader.py
This Python script has a function called "getkey(loc)" that takes the location of a text file as argument. The text file contains a PUBLIC KEY. The function reads the entire content and splits them at '\n' to create a list. Each item in the list is then converted to an HTML line and printed.
-
template_engine.py
This script is completely responsible for generating the entire webpage. It has several function that generate the required HTML code. To make sure that printed strings are interpreted as HTML code by the browser a function specifies the CGI Content.
Content type: text/html \n\n
This WebApp requires Python3. Get Python3 from here
Clone the project from here
- After cloning the project open terminal and change directory to webapp/
$ cd webapp
Start the HTTP Server with following command
$ python simple_httpd.py
You should see the following output on terminal
This means the server is ready to take requests
DON'T CLOSE THIS TERMINAL
- Open your web browser and type localhost:8080
You should see the following output on terminal
- On the browser you should see this webpage
- Click on the WebApp link and you should see successfull execution message in terminal
- A new dynamic webpage will be generated like this
To stop the web server simply close the terminal or press [Ctrl + C] in the terminal
- Shashank Singh - shashank9830
This project is licensed under the MIT License - see the LICENSE.md file for details