Skip to content

Commit 86f8f08

Browse files
committed
Flask Template learned
1 parent cbbd764 commit 86f8f08

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#build the flask app
77

88
@app.route("/")
9-
#tells the url - nothing means everything
9+
#tells the url - currently / means home
1010
def hello():
1111
return "Hello World!"
1212

02.Flask/01.Templates.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#make static folder for public view
2+
#make template folder for private view
3+
4+
from flask import Flask, render_template
5+
#render_template function html ko python se link karta hai
6+
7+
app = Flask(__name__)
8+
9+
@app.route("/")
10+
def template():
11+
return render_template("index.html")
12+
#file location bydefault templates folder ka hota hai
13+
14+
#To link python variables to html
15+
@app.route("/variable")
16+
def variable():
17+
myname = "Harsh"
18+
return render_template("variable.html", naam = myname)
19+
#To use this variable in html use {{naam}}
20+
21+
app.run()

02.Flask/templates/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
</head>
99

1010
<body>
11+
<p>Ye template page hai<p>
1112
</body>
1213

1314

14-
</html>
15+
</html>

02.Flask/templates/variable.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
3+
<html>
4+
5+
6+
<head>
7+
<title>About Page</title>
8+
</head>
9+
10+
<body>
11+
<h1>Hi mera naam {{naam}} hai</h1>
12+
</body>
13+
14+
15+
</html>

0 commit comments

Comments
 (0)