Notes#
- Studied Flask framework for 76 days.
- Flask is a web framework for Python used to build web applications.
- The usage of Flask feels mismatched.
- Use
static_url_path
to configure the directory for accessing static resources. app.route
defines the route access.@app.route('/')
is the root directory, and Flask will automatically call theindex()
function.- Today's code exercise is to write two pages, and I have briefly written them.
- Skipped recording the content of learning HTML and CSS for days 73-75 because it was too simple.
CODE#
from flask import Flask
import datetime # import the datetime library
app = Flask(__name__, static_url_path="/static")
@app.route('/')
def index():
page = f"""
<html>
<head>
<title>David's World Of Baldies</title>
</head>
<body>
<h1>Two Links</h1>
<h2><a href=/portfolio>portfolio</a></h2>
<h2><a href=/linktree>linktree</a></h2>
</body>
</html>
"""
return page
@app.route('/portfolio')
def portfolio():
page = f"""
<html>
<head>
<title>portfolio</title>
</head>
<body>
<h1>portfolio</h1>
<p>This is portfolio</p>
<p><img src=static/images/picard.jpg/></p>
<p><a href=/>Go Home</a></p>
</body>
</html>
"""
return page
@app.route('/linktree')
def linktree():
page = f"""
<html>
<head>
<title>linktree</title>
</head>
<body>
<h1>linktree</h1>
<p>This is linktree</p>
<p><a href=/>Go Home</a></p>
</body>
</html>
"""
return page
app.run(host='0.0.0.0', port=81) # Missed the run command
Translation: