Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!