How can I redirect HTTP requests through a python script?

I carefully searched for the answer to my question, but I don’t think I know the right terminology to make my searches effective. Anyway, I want to configure my web server to route a request to a static page through the Python "PageBuilder" program, which will dynamically embed content in templates.

In other words:

  • mysite.com/index.html user requests
  • server sends request to specific python script (my server is currently Apache2)
  • python script generates output, transfers output to server
  • the server serves content for the user

Can someone help me or at least give me the “correct terminology” for the search?

+3
source share
2 answers

This is no longer static content. You want to dynamically generate content using a script.

In Python, this is usually done using the WSGI interface ( CGI was the de facto standard in the past ), which defines the standard way to enter Python code (HTTP request information) and send a response (HTTP headers and the content you want to serve - usually HTML )

For this purpose, there is an excellent mod_wsgiApache module that configures the plumbing between the server (receiving requests and sending back content) and your code using this WSGI interface.

- templating, HTML ( Jinja2).

+4

All Articles