dimanche 22 septembre 2019

How to display a python page with python http server?

I'm trying to display a python page using the simple python3 server. The server works, but the python page is not interpreted by the server, it is displayed in plain text. I can find thousands of tutorials to display an html page, but not a python content. See code below for the server and the page, what am i doing wrong ?

Server :

#!/usr/bin/python
# -*- coding: latin-1 -*-

import http.server
import socketserver

# Serveur http de base delivrant le contenu du repertoire courant via le port indique.
PORT = 8080
## Python 3 :
Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("",PORT), Handler)
print("Ecoute sur le port :", PORT)
httpd.serve_forever()

Page :

#!/usr/bin/python
# coding: utf-8

print("Content-type: text/html; charset=utf-8\n")

html = """<!DOCTYPE html>
<head>
    <title>Mon programme</title>
</head>
<body>
test</body>
</html>
"""
print(html)




Aucun commentaire:

Enregistrer un commentaire