Skip to content

Commit

Permalink
starting files add
Browse files Browse the repository at this point in the history
  • Loading branch information
armanchhetri committed Jul 7, 2021
1 parent 295cda4 commit 22b4f3d
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 0 deletions.
17 changes: 17 additions & 0 deletions hello_app/app.py
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()
52 changes: 52 additions & 0 deletions request_and_forms/app.py
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)
16 changes: 16 additions & 0 deletions request_and_forms/templates/form.html
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>
15 changes: 15 additions & 0 deletions request_and_forms/templates/message.html
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>
102 changes: 102 additions & 0 deletions template_and_layout/app.py
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)
23 changes: 23 additions & 0 deletions template_and_layout/templates/conditional_msg.html
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>
17 changes: 17 additions & 0 deletions template_and_layout/templates/index.html
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>
15 changes: 15 additions & 0 deletions template_and_layout/templates/message.html
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>
18 changes: 18 additions & 0 deletions template_and_layout/templates/multiple_msg.html
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 template_and_layout/templates/new_templates/conditional_msg.html
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 %}
10 changes: 10 additions & 0 deletions template_and_layout/templates/new_templates/index.html
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 %}

16 changes: 16 additions & 0 deletions template_and_layout/templates/new_templates/layout.html
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>
14 changes: 14 additions & 0 deletions template_and_layout/templates/new_templates/message.html
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 template_and_layout/templates/new_templates/multiple_msg.html
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 %}

0 comments on commit 22b4f3d

Please sign in to comment.