In: Computer Science
Make a modest or simple Web page using Python flask. The basic components of HTML should be included. The Web page should have at least 3 Headings(<h1>), paragraph (<p>), comments (<!-- -->), ordered list, unordered list, three links to website, and should display time & date.
Example:
<html>
<head>
<title>Page Title</title>
</head>
<body>
..new page content..
</body>
</html>
Code:
main.py
from flask import Flask,redirect,url_for,render_template
import datetime
app=Flask(__name__) #flask class object
@app.route('/') #to navigate from one page to another we use route function
#@ decorator
def index():
x = datetime.datetime.now() # to get date and time
return render_template('basic.html',date=x)
if __name__=='__main__':
app.run(host="127.0.0.1",debug="True") #set your host number and debug == true
main.py code in image:
basic.html
<htm>
<head>
<title>Page Title</title>
</head>
<body>
<!--Three headings-->
<h1>THis is h1 heading</h1>
<h2>THis is h2 heading</h2>
<h3>THis is h3 heading</h3>
<p>This is a Paragraph</p>
<!-- This is order list -->
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<!-- This is unorder list -->
<ul style="list-style-type:disc;">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<!--{{date.year}} is used to print the current year from the date obtained in main.py, similarly month, day, hour,minute and second-->
<p>Date: {{date.year}}-{{date.month}}-{{date.day}}</p>
<p>Time: {{date.hour}}:{{date.minute}}:{{date.second}}</p>
<!--Three links to website-->
<a href="http://google.co.in">Link to google</a><br>
<a href="http://google.co.in">Link to google</a><br>
<a href="http://google.co.in">Link to google</a><br>
</body>
</htm>
basic.html in image with comments:
Explanation:
The basic.html is rendered by the main.py file in the given server i.e(127.0.0.1 in our case).
The datetime library is imported in main.py file and the value is sent to basic.html.
basic.html file should be stored in templates folder of flask.
Output: