问题
For one of my classes last semester I had to create a website using a CGI script. While it was a good introduction to web development, but I can see it has it's limitations. So my question is, in the industry today, what is the most common approach for parsing a Python script into html?
I have found a few posts on Stack Overflow that suggest FastCGI for PHP, but I am wondering if the same answers apply to Python.
回答1:
I assume that I would use .py rather than .cgi? If that's the case, how would a web server know to run it?
This is a old way of thinking :)
Nowadays you start your Python process, and it begins to listen on a port. The Python process itself contains a webserver and is almost completely self-contained - see here for the different webservers you can use within your Python process - gunicorn is a popular one.
Of course a lot of people still put Nginx or Apache in front of their Python process as a "reverse proxy". Essentially this is to handle SSL/TLS but also sometimes to do load balancing, custom error pages if your Python process is down etc.
回答2:
WSGI is a protocol that describes (synchronous) communication between a web server and a web application. https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface
来源:https://stackoverflow.com/questions/34540936/what-is-considered-the-current-industry-standard-alternative-to-cgi-for-python-w