I am trying to do some basic D3 programming. All the books I am reading talk about setting up a local http server and that is where I am finding myself stuck. I typed the following
python -m http.server
to host the local server. Now, my problem is how to open my html file in this local server? I don't even know how to find the file in the command prompt. Any help will be appreciated. The following is my html file code on aptana. I also have put the d3.js file in the aptana.
D3 Page Template
//D3 codes will go here
When I am running aptana, the html file is opening in a regular firefox page. I want it to open in the locally hosted http server page. Any hints.
解决方案
The answer is provided when you start the server. In the same directory where you have your HTML file, start the server:
$ python -m http.server
Serving HTTP on 0.0.0.0 port 8000 ...
(Or, the Python2 incantation)
$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
In this message, Python tells you the IP address (0.0.0.0) and the port number (8000).
So, if the file is named d3_template.html, you can get to this page via http://0.0.0.0:8000/d3_template.html
On most machines you should also be able to use
http://localhost:8000/d3_template.html
or
http://127.0.0.1:8000/d3_template.html
If you get an error like this:
socket.error: [Errno 48] Address already in use
You want to use a different port:
$ python -m http.server 8888
And to load the file:
http://0.0.0.0:8888/d3_template.html
To understand why all of these work, you'd want to learn a fair bit about networking (ports, DNS, loopback interface, how multiple network cards behave on the same machine and, if things aren't working as expected, firewalls, restricted ports and who knows what else).