Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 669
Tharun M Avatar asked Jul 19 '26 23:07

Tharun M


1 Answers

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
like image 165
NemoMeMeliorEst Avatar answered Jul 21 '26 11:07

NemoMeMeliorEst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!