Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I am working on some basic D3 programming. All I have learned is how to set up the local HTTP server and that is where I am stuck. When I am giving the below code to the host of the local server:

python -m http.server 

How can I open my HTML file on this local server? The following is my HTML file code on Aptana. I also have put the d3.js file in the Aptana.

<!DOCTYPE html>

<html lang="en">

    <head>

        <meta charset="utf-8">

        <title>

            D3 Page Template

        </title>

        <script type="text/javascript" src="d3.js"></script>

    </head>

    <script type="text/javascript">

        //D3 codes will go here

    </script>

</html>

I want it to open on the locally hosted HTTP server page. Kindly guide me

1 Answer

0 votes
by (107k points)

You need to start the server in the same directory where you have your HTML file:

$ 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 ...

This python code will inform you of the IP address (0.0.0.0) and the port number (8000).

If the file name is d3_template.html, you can direct to that page via http://0.0.0.0:8000/d3_template.html

You can use this also:

http://localhost:8000/d3_template.html or http://127.0.0.1:8000/d3_template.html

If you get something like this:

socket.error: [Errno 48] Address already in use

You will then have to use a different port:

$ python -m http.server 8888

And to load the file:

http://0.0.0.0:8888/d3_template.html

Want to become a Python Developer? Check out this insightful Python Certification

Related questions

0 votes
1 answer
asked Aug 4, 2020 in AWS by Amyra (12.9k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...