Friday, May 29, 2015

Python: SimpleHTTPServer

Whats nice about building a website is that you can just change the resolution on the desktop browser and see how the page renders on a smaller resolution, right? Wrong. At least In my experience I've found it to be invaluable to review the website on an actual mobile devices. Evidently this command is one of the most popular terminal commands. It's definitely one of my favorites.

Challenge: Review a website on mobile devices.

Solution: Use pythons SimpleHTTPServer to host the pages on a local port from the command line using

$ python -m SimpleHTTPServer 2000

The command  $ python -m .. is used to run a python module. In this case I am using the SimpleHTTPServer module which will serve the files of the current directory. This module has been merged to http.server in Python3. Running this command with the argument 2000 servers the files to the local server to that port When I did not specify the port it defaulted  to port 8000.

On my mobile devices, that were hooked up to the local internet,  I just entered the local ip address of my computer followed by :2000, my specified port. To find the  ip address of my computer I used the command $ ifconfig | grep "inet". Looking it up now, this one $ ifconfig | grep "inet" | grep -v | cut -d\ -f2 is better because my command returns multiple inet addresses and extra text.

No comments:

Post a Comment