spacebar
to navigate to the next slides
for speaker notesWe can subtract points for bad code style and practices.
In case of any problem (e.g. illness) notify the teacher immediately!
Cooperation allowed! Just do not disturb others.
Log in to a website (e.g. SIS):
Inspired by Python tutorial. This is NOT a production code!
#!/usr/bin/env python3
from http.server import BaseHTTPRequestHandler, HTTPServer
HOST = "localhost"
PORT = 8080
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html; charset=utf-8")
self.end_headers()
self.wfile.write(bytes("<!doctype html><title>My Page</title>", "utf-8"))
if __name__ == "__main__":
server = HTTPServer((HOST, PORT), MyServer)
try:
server.serve_forever()
except KeyboardInterrupt:
pass
server.server_close()
Using self we can access information about the request.
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
# Previous content ...
self.wfile.write(bytes(f"<p>Request: {self.path} </p>" , "utf-8"))
Use Python to server the content.html file you've created. You can build on the given Python example.
Read values from URL query and substitute them into the file.
For example query: ..?name=Ailish&age=19 and template:
<p>{name} is {age} years old.</p>
Should produce output:
<p>Alilis is 19 years old.</p>
Add support for code execution like conditions, cycles, functions, ...
Run following command to server content of current directory:
python3 -m http.server
Add at the end of the do_GET method.
with open("content.html", "rb") as stream:
self.wfile.write(stream.read())
Content of public_html is available at https://webik.ms.mff.cuni.cz/~<username>/
.
You can connect to remote machine using your IDE. Remote development using VS Code. Keep in mind that webik has limited resources!
ssh -p 42222 <username>@webik.ms.mff.cuni.cz
scp -P42222 index.html <username>@webik.ms.mff.cuni.cz:public_html/
Host webik
HostName webik.ms.mff.cuni.cz
User <username>
Port 42222
Now you can use just: ssh webik
https://webik.ms.mff.cuni.cz/~<username>/
.Leave an anonymous feedback.