GithubHelp home page GithubHelp logo

4n3i5v74 / python-cgi-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nbeaver/python-cgi-example

0.0 1.0 0.0 14 KB

A simple server and hit counter entirely in Python designed to demonstrate how to write CGI scripts.

License: MIT License

Makefile 11.12% Python 88.88%

python-cgi-example's Introduction

Simple python3 cgi script.

Quickstart

Clone the repo:

git clone https://github.com/nbeaver/python-cgi-example

Move into the directory:

cd python-cgi-example

Run this command:

python3 ./http_server.py

This should open a browser page showing the current date and a hit counter that increases each time the page is reloaded.

Modify cgi-bin/hit_counter.py and reload the page to see the effects.

Hit Ctrl-C to stop the web browser once you are finished.

Motivation

Most tutorials for Python CGI scripts I have seen have flaws such as:

  • Requiring installation of a web server like apache instead of just serving from a local directory using Python's SimpleHTTPServer.
  • Requiring write access to directories like /var/www/cgi-bin/.
  • Not opening the browser to the correct page when the server starts.
  • Not storing the cgi script in a separate directory from the server source code.
  • Not providing the code in a convenient bundle to download, run, and modify.

as well as pedagogical flaws such as:

  • Not distinguishing the HTTP header from the HTML.
  • Sending plain text instead of HTML.
  • Sending static HTML instead of dynamic output.
  • Sending dynamic output that could be done entirely client-side.

The included CGI script is a simple hit counter that writes to a file on disk to store the count.

Note

This is a pedagogical exercise, and is not the best way to implement a hit counter in general.

python-cgi-example's People

Contributors

nbeaver avatar 4n3i5v74 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.