I have done this myself but probably using the long way around approach but it was an interesting and satisfying learning experience. I used basic Python as much as possible to be able to understand what was going on. I was prepared to experiment to increase my understanding.
I proceeded as follows:-
1) Using information on Tutorialspoint I created a simple HTML server that ran on my LAN (192.168.0.9:8080 note port number at end which is for port forwarding later).
https://www.tutorialspoint.com/python3/ ... orking.htm
2) In the simple server I grabbed and displayed (using print) the first 1024 (more than really needed) characters that arrive from the client (a browser) to see how a browser talks to a server.
3) From 2) I noticed that the browser sends a GET / string as follows:-
GET /hello (when I went to 192.168.0.9:8080/hello)
4) I then had my simple server extract the text after the / and test with if statements to turn the leds on/off
192.168.0.9:8080/led1on (I extract led1on after the GET / and turn the led on etc)
5) I then learned how to do Port Forwarding in my router so that I could use my WAN IP from outside the router. The router manual along with some
Google and YouTube helped here. I tested again and all was OK.
6) I then learned some HTML to be able to create a simple webpage with buttons that inserted the /led1on etc into the HTTP address line. I read up
on the "a href' and 'button' tags to be able to do this.
7) I modified my server to send the webpage HTML file to the client on connection with the client and extract the GET / from the client.
All in all it was quite a lot of work but taking it one step at a time I could see the finished product developing and I had an understanding of my code.
As other posters have shown, there are more sophisticated approaches using ready made web tools but I feel that a simpler approach with a deeper understanding and the ability to explain every step is more appropriate for a student project.