

We will use HTML to write the code for the webpage. Basically, we are telling our router to forward any requests that come to port 80 and send the requests to the Raspberry Pi. This is a procedure that allows computers on the internet to connect to a specific service within our private network. One particular procedure that we can do is called Port Forwarding. For external users to access our webserver from the internet, we will need to change a few settings on our router. Port ForwardingĪt this point, our web page can only be accessed by computers that are on the same network as the Raspberry Pi. Note that if the website is running on a different port, you need to include it in the URL as follows: 192.168.8.39:80/hello. Now open your browser and type 192.168.8.39/hello. You can do this by running this command from the Raspberry Pi terminal: sudo python myServer.py The next step is to start the server in your terminal. You can also try doing the same procedure on a different computer but make sure that it is on the same network with the Raspberry Pi.įrom this we can see that our server is up and running and three devices from the same network have successfully accessed our website. Next, open your preferred browser, then enter the IP address, port number, and route name as shown below and you will see “Hello there” in the browser. Specify the host and the port (it can be the local host, or the IP address if you know it). Finally, tell the Python interpreter to run the built-in development server: run(host='137.158.131.117', port=8080, debug=True).


Next, return "Hello there." This function will simply return a text which says “Hello there…” in your web browser.Then, define a function that will be executed when the route is called: def hello().In this case, it’s going to be '/hello', but it can be anything you want to call it. Use the decorator followed by the actual location of the route.First, import route and run from the bottle library: from bottle import route, run.To create a route, follow the following steps: Run(host='192.168.8.39', port=80, debug=True, reloader=True) Code DescriptionĪ web application cannot work without routes. Run the command: sudo python myServer.py. Then copy the code below into your file and hit Ctrl-X, Y, then press the Enter key to save and exit. To build a basic web server, create a Python file and give it any name.
