How to serve your webpage within a directory from localhost easily?
 |
Python SimpleHTTPServer |
Python simple server
To determine if your computer has python installed. you can open up your terminal or command prompt and type in the following command. Check out
Google Open Online Education document for more information.
 |
Python Homepage |
Macbook
Type either one of the following command on terminal to check the version of installed python
python -V
OR
python --version
Windows
Type this command on Command Prompt to retrieve the version of installed python
Commands
If you are using
python version 2 simplehttpserver, run this command on your terminal or cmd:
python -m SimpleHTTPServer
If you are using
python version 3 http.server, run this command on your terminal or cmd:
python3 -m http.server
Note
1) The entry point is the index.html within the directory.
2) It doesn't work if you have files from multiple directories.
3) Your current directory is the root of your webpage. Your relative links on the page should be based on this perspective.
4) If you wonder what the difference between serving your file from localhost and opening your index.html file on a browser? Check out this
StackOverflow thread.
In short, serving your file from localhost is simulating serving your files from a real server.
Thanks for reading!
Jun
Comments
Post a Comment