in other words: how to print-output a lot of <html> special characters inline from a python script, that is run by apache2 webserver.

how hard can it be right?

configure apache2 (on CentOS7, RHEL7 it is called httpd) to recognize and run python.py scripts.

vim index.py

#!/usr/bin/env python3
""" this will allow to use inline python for dynamic website output :) """
__author__ = "user@domain.com"
import sys
sys.stdout = open(sys.stdout.fileno(), mode="w", encoding="utf-8", newline=None, buffering=1)

print("Content-Type: text/html")
print()
print("""
<html>
<head>
crazy html js css goes here 
</head>
<body>
</body>
</html>
""")

creditz:

thanks to Johann Patrak: “learned the hard way that Python does not always use UTF-8 for sys.stdin/stderr/stdout.”

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin