Python + HTML
http://vh7.uk/zd
Flask is what we will use to make a web server using Python.
mkdir web
cd web
touch firstwebsite.py
nano firstsite.py
python3 firstsite.py
jake.malverncode.club
Challenge: Try and make a new page.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "Hello!"
if __name__ == "__main__":
app.run("0.0.0.0", 8091)
Leave this, just press enter
http://vh7.uk/zd
mkdir templates
cd templates
nano page.html
cd ../
nano firstsite.py
Try and add some more pages and link them together.
from flask import Flask, render_template
@app.route("/")
def index():
return render_template("page.html")
http://vh7.uk/zd
Now try updating your code to this: Try and work out what's happening. See if you can edit it.
server.py
templates/hello.html
from flask import Flask, render_template
app = Flask(__name__)
# ... other routes ...
@app.route("/hello/<name>")
def index():
return render_template("hello.html", name=name)
if __name__ == "__main__":
app.run("0.0.0.0", 8091)
<h1>Hello {{name}}!</h1>
http://vh7.uk/zd
Now go to {YOUR_NAME}.malverncode.club/hello/you
Create a fully functioning website about you. Add links between different pages and ask for help if you thing of a good idea but don't know how you would do it.
Unfortunately, that's the end of the lesson. Save your work and just close the tab.
Next week we will either be continuing the work this week or using APIs.