Search code examples
pythonhtmlserverxampplocalhost

Host a local html file in localhost using python alone


I am running a code on a remote server that periodically generates a "status" html(something like a tensorboard say) and stores it in a folder in the server. Currently I download the html file whenever I want to check the status. If I can host the generated html using python into the server's localhost:p1, I can simply view the html in my local machine using

ssh -N -f -L localhost:p1:localhost:p1 servername

I know that people use xampp/wamp to put local html files in localhost. Is there a way to do this with python alone?


Solution

  • For Python 3, go to working directory where the files are located. Then run:

    python3 -m http.server 8000
    

    Now open a browser and navigate to localhost:8000.


    For Python 2:

    python -m SimpleHTTPServer 8000