Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
How do you use the http.server python module to run HTML+Javascript+CSS?

I am trying to create a simple python server using the http.server module. My python code looks like this:

from http.server import HTTPServer, BaseHTTPRequestHandler

class helloHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/':
            self.path == '/mainprogram.html'
        try:
            file_to_open = open('mainprogram.html').read()
            self.send_response(200)
        except:
            file_to_open = "file not found"
            self.send_response(404)
        self.send_header('content-type', 'text/html')
        self.end_headers()
        self.wfile.write(bytes(file_to_open, 'utf-8'))

def main():
    PORT = 8000
    server = HTTPServer(('', PORT),helloHandler)
    print('Server running on port %s' % PORT)
    server.serve_forever()

if __name__ == "__main__":
    main()

This serves my HTML page on the server but it doesn't run my javascript and CSS files. So the skeleton of my page is there i.e. text, buttons, search bars but none of the functionality is there and the styles aren't applied.

I have written separate CSS and Javascript files and have included them in my HTML file like this:

<link rel="stylesheet" href="styles.css">
<script src="scriptfile.js"><script>

Please help! I am a beginner to all this so I have no clue

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda