-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
295cda4
commit 22b4f3d
Showing
14 changed files
with
350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from flask import Flask | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.route('/') | ||
# Define an index function to return "Hello World!!" | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
if __name__=="__main__": | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from flask import Flask, render_template, request | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
|
||
|
||
@app.route('/') | ||
def index(): | ||
return render_template("form.html") | ||
|
||
|
||
|
||
|
||
####------------------STEP 1: request introduction and ------------------------------------------### | ||
|
||
@app.route('/message') | ||
def message(): | ||
message = request.args.get('msg') | ||
return render_template('message.html', msg=message) | ||
|
||
|
||
####----------------------STEP 2: form and http methods -----------------------------------------### | ||
|
||
# @app.route('/message',methods=["GET","POST"]) | ||
# def message(): | ||
# message = request.form.get('msg') | ||
# return render_template('message.html', msg=message) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
####-----------------------STEP 3: GET and POST using same endpoint---------------------------------### | ||
# @app.route('/', methods=["GET","POST"]) | ||
# def index(): | ||
# if request.method == "GET": | ||
# return render_template("form.html") | ||
|
||
# if request.method == "POST": | ||
# message = request.form.get('msg') | ||
# return render_template('message.html', msg=message) | ||
|
||
|
||
|
||
|
||
|
||
if __name__=="__main__": | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Software Fellowship</title> | ||
</head> | ||
<body> | ||
<form action="/message" method="GET"> | ||
<input placeholder="your message" type="text" name="msg"> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Software Fellowship</title> | ||
</head> | ||
<body> | ||
<div style="text-align: center; margin-top:10%;"> | ||
User Says {{ msg }} | ||
</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
from flask import Flask, render_template | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
|
||
# TO COMMENT OR UNCOMMENT [Ctrl + /] | ||
|
||
#-----------------------------------------------Without Layout-----------------------------------------------------------------# | ||
|
||
##--------------------------------------STEP 1: simple templating rendering---------------------------------------------------# | ||
@app.route('/') | ||
def index(): | ||
return render_template("index.html") | ||
|
||
|
||
|
||
###--------------------------------------STEP 2: template render with arguments passing and Jinja variables--------------------# | ||
# @app.route('/') | ||
# def index(): | ||
# ''' Pass message as msg to render template function''' | ||
|
||
# message = "Hello, how are you?" | ||
# return render_template("message.html") | ||
|
||
|
||
|
||
|
||
|
||
###---------------------------------------STEP 3: template rendering [conditionals]------------------------------------------------# | ||
# @app.route('/') | ||
# def index(): | ||
# ''' Pass message as msg and show as show from render_template''' | ||
# show = True | ||
# message = "Hello, how are you?" | ||
# return render_template("conditional_msg.html") | ||
|
||
|
||
|
||
|
||
|
||
###-----------------------------------------STEP 4: template rendering multiples [loop]---------------------------------------------# | ||
# @app.route('/') | ||
# def index(): | ||
# ''' Pass multi_message as messages from render_template''' | ||
|
||
# multi_message = ["Hello", "How are you?", "I am learning flask."] | ||
# return render_template("multiple_msg.html") | ||
|
||
|
||
|
||
|
||
|
||
|
||
#########----------------------------------------Using Layout-------------------------------------------------------------########## | ||
|
||
###--------------------------------------STEP 1: simple templating rendering---------------------------------------------------# | ||
# @app.route('/') | ||
# def index(): | ||
# return render_template("new_templates/index.html") | ||
|
||
|
||
|
||
|
||
|
||
###--------------------------------------STEP 2: template render with arguments passing and Jinja variables--------------------# | ||
# @app.route('/') | ||
# def index(): | ||
# message = "Hello how are you?" | ||
# return render_template("new_templates/message.html", msg=message) | ||
|
||
|
||
|
||
|
||
|
||
###---------------------------------------STEP 3: template rendering [conditionals]------------------------------------------------# | ||
# @app.route('/') | ||
# def index(): | ||
# show = True | ||
# message = "Hello how are you?" | ||
# return render_template("new_templates/conditional_msg.html", show=show, msg=message) | ||
|
||
|
||
|
||
|
||
|
||
###-----------------------------------------STEP 4: template rendering multiples [loop]---------------------------------------------# | ||
# @app.route('/') | ||
# def index(): | ||
# ''' Pass multi_message as messages from render_template''' | ||
|
||
# multi_message = ["Hello", "How are you?", "I am learning flask."] | ||
|
||
# return render_template("new_templates/multiple_msg.html") | ||
|
||
|
||
|
||
|
||
|
||
|
||
if __name__=="__main__": | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Software Fellowship</title> | ||
</head> | ||
<body> | ||
<div style="text-align: center; margin-top:10%;"> | ||
{% if show %} | ||
|
||
User says: {{msg}} | ||
|
||
{% else %} | ||
|
||
User says: Nothing | ||
|
||
{%endif%} | ||
</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<title>Software Fellowship</title> | ||
</head> | ||
<body> | ||
<div style="text-align: center; margin-top:10%;"> | ||
User Says Hello World | ||
</div> | ||
|
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Software Fellowship</title> | ||
</head> | ||
<body> | ||
<div style="text-align: center; margin-top:10%;"> | ||
User Says {{ msg }} | ||
</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Software Fellowship</title> | ||
</head> | ||
<body> | ||
<div style="text-align: center; margin-top:10%;"> | ||
User says Multiple messages: | ||
{% for msg in messages %} | ||
<p>{{msg}}</p> | ||
{%endfor%} | ||
</div> | ||
|
||
</body> | ||
</html> |
21 changes: 21 additions & 0 deletions
21
template_and_layout/templates/new_templates/conditional_msg.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% include 'new_templates/layout.html' %} | ||
|
||
|
||
|
||
{% block message%} | ||
|
||
<div style="text-align: center; margin-top:10%;"> | ||
User Says message using Layout:<br> | ||
|
||
{% if show %} | ||
|
||
|
||
{{ msg }} | ||
|
||
{% else %} | ||
|
||
Nothing | ||
|
||
{%endif%} | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% include 'new_templates/layout.html' %} | ||
|
||
|
||
|
||
{% block message%} | ||
<div style="text-align: center; margin-top:10%;"> | ||
User Says Hello World Using Layout | ||
</div> | ||
{% endblock %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<title>Software Fellowship</title> | ||
</head> | ||
<body> | ||
|
||
{% block message %} | ||
{% endblock %} | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% include 'new_templates/layout.html' %} | ||
|
||
|
||
|
||
{% block message%} | ||
|
||
<div style="text-align: center; margin-top:10%;"> | ||
With message passing Using Layout | ||
User Says {{ msg }} | ||
</div> | ||
{% endblock %} | ||
|
||
|
||
|
14 changes: 14 additions & 0 deletions
14
template_and_layout/templates/new_templates/multiple_msg.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% include 'new_templates/layout.html' %} | ||
|
||
|
||
|
||
{% block message%} | ||
<div style="text-align: center; margin-top:10%;"> | ||
User says Multiple messages Using Layout: | ||
{% for msg in messages %} | ||
<p>{{msg}}</p> | ||
{%endfor%} | ||
|
||
</div> | ||
{% endblock %} | ||
|