2
2
main.py:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
if __name__ == '__main__':
app.run(debug=True)
statics:
style.css:
/* static/style.css */
body {
background-color: #f2f2f2;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: #333;
text-align: center;
padding: 50px;
}
h1 {
color: #2c3e50;
}
p{
font-size: 18px;
margin-top: 10px;
}
a{
display: inline-block;
margin-top: 20px;
text-decoration: none;
color: #fff;
background-color: #3498db;
padding: 10px 20px;
border-radius: 5px;
transition: background-color 0.3s ease;
}
a:hover {
background-color: #2980b9;
}
Templates:
home.html:
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<h1>Welcome to the Home Page!</h1>
<p>This is the main page of the Flask app.</p>
<a href="/about">Go to About Page</a>
</body>
</html>
about.html:
<!DOCTYPE html>
<html>
<head>
<title>About Page</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<h1>About This Application</h1>
<p>This Flask web app was created using HTML templates.</p>
<a href="/">Back to Home</a>
</body>
</html>
Output: