In: Computer Science
Generate a modest Web page via Python flask. It should include basic components of HTML. The Web page should have at least three Headings(<h1>), a paragraph (<p>), comments (<!-- -->), ordered list, unordered list, three links to website, and should display time & date.
Hi,
The following is the python code and HTML page for this assignment.
Please ensure the following
1. Install Flask module with the command - "pip install
flask"
2. Copy the server.py file
3. Create a sub folder in the current location with name
"templates"
4. Copy the index.html to the "templates" folder
5. Please ensure the server.py is correctly indented (refer to
screenshot)
If you have any issues or questions, please leave me a comment. I shall help you in resolving them.
If this solution helps with your assignment, please do upvote.
Thank you.
#server.py
from flask import Flask
from flask import render_template
import datetime
#Initialize the Flask app
app = Flask(__name__)
#Handle the default route
@app.route("/")
def home_page():
#Get the current date/time and format it
now = datetime.datetime.now()
current_date_time = now.strftime("%Y-%m-%d %H:%M:%S")
#Display the HTML page in templates folder and pass the
datevar
#to the template
return render_template("index.html", datevar=current_date_time)
if __name__ == "__main__":
app.run()
### index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Python Flask Example</title>
</head>
<body>
<h1>This is a Heading #1</h1>
<h1>This is a Heading #2</h1>
<h1>This is a Heading #3</h1>
<p>And I am paragraph</p>
<!-- This is a comment and I am not visible in the browser -->
<ol>
<li>
Ordered List Item #1
</li>
<li>
Ordered List Item #2
</li>
</ol>
<ul>
<li>
UnOrdered List Item #1
</li>
<li>
Ordered List Item #2
</li>
</ul>
<a href="https://www.google.com">I am a link to Google
</a> <br>
<a href="https://www.uber.com">I am a link to Uber </a>
<br>
<a href="https://www.tesla.com">I am a link to Tesla
</a> <br>
Current Date and Time is: {{ datevar }}
</body>
</html>
######## Output #########