Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda