Unit 13
index.html (version 1)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello, World!</title>
</head>
<body>
Hello, World!
</body>
</html>
style.css
body {
background-color: #f0f0f0;
color: #333;
}
.container {
padding: 20px;
background-color: white;
border-radius: 10px;
width: 50%;
margin: auto;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
a {
color: blue;
text-decoration: none;
}
index.html (version 2)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello, World!</title>
</style>
<link rel="stylesheet" href="style.css">
</head>
<body>
Hello, World!
<p style="color: red;">This is red text</p>
<h1>I am feeling blue</h1>
</body>
</html>
search.html
<html>
<head>
<title>hello</title>
</head>
<form>
<input name="q">
<input type="submit">
</form>
</html>
app.py (version 1)
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return "Hello, Flask!"
if __name__ == '__main__':
app.run(debug=True)
app.py (version 2)
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template("home.html")
if __name__ == '__main__':
app.run(debug=True)
home.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>hello</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
hello, {{ placeholder }}
</body>
</html>
app.py (version 3)
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route('/greet', methods=['POST'])
def greet():
username = request.form['name']
return f"Hello, {username}!"
if __name__ == '__main__':
app.run(debug=True)
index.html (version 3)
<!DOCTYPE html>
<html lang="en">
<head>
<title>hello</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Welcome to My Homepage!</h1>
<form method="POST" action="/greet">
<input type="text" name="name" placeholder="Enter your name">
<input type="submit" value="Greet Me">
</form>
</body>
</html>
app.py (version 4)
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route('/user/<username>/<int:age>')
def show_user(username, age):
return render_template('index.html', username=username, age=age)
if __name__ == '__main__':
app.run(debug=True)
index.html (version 4)
<!DOCTYPE html>
<html>
<head>
<title>User Info</title>
</head>
<body>
<h1>User Profile</h1>
<p><strong>Username:</strong> {{ username }}</p>
<p><strong>Age:</strong> {{ age }}</p>
</body>
</html>
Last updated