Skip to content

Commit

Permalink
Practice
Browse files Browse the repository at this point in the history
  • Loading branch information
ByeonghoonJeon committed Jul 23, 2021
1 parent c4d1496 commit 174ae9c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 17 deletions.
58 changes: 41 additions & 17 deletions flaskPractice/main.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,73 @@
# WHY = seperate the python code from the HTML code and make it scalable!

# import the flask library for usage
from flask import Flask, request
from flask import Flask, request, render_template
# creat an instance of the flask server
# as the root directory within 'main.py'
app=Flask(__name__)
app = Flask(__name__)

# create some routes


#create some routes
@app.route('/')
def displayHompage():
return "<h1>Welcome to your first website</h1>"
return render_template('index.html')


@app.route('/route1')
def route1Info():
return"<h3>Congrats you made route 1</h3>"

# <> denotes a route variable.


@app.route('/profile/<users_name>')
def profile(users_name):
return"<h2>Hello, " + users_name + "!</h2>"


@app.route("/date/<month>/<day>/<year>")
def displayGivenDate(month, day, year):
return f"{month} / {day} / {year}"

# creating a <form>
formData = f"""
<form action="/results" method="POST">
What's your favorite pizza flavor?
<input type="text" name="pizza_flavor">
<br>
What's your favorite crust type?
<input type="text" name="crust">
<input type="submit" value="submit pizza">
</form>
"""


@app.route("/formExample")
def firstForm():
return formData
return render_template('form.html')


@app.route("/results", methods=['POST'])
def resultPage():
pizza_flavor = request.form.get("pizza_flavor")
crust = request.form.get("crust")
return f"<h3>A {crust} crust {pizza_flavor} pizza has been ordered!</h3>"
return f"<h3>A {crust} crust {pizza_flavor} pizza has been ordered!</h3>"


@app.route('/pizza/submit', methods=['GET', 'POST'])
def submit_pizza():
users_email = request.args.get('email')
users_phone = request.args.get('phone')
crust_type = request.args.get('crust')
pizza_size = request.args.get('size')
list_of_toppings = request.args.getlist('toppings')
accepted_terms = request.args.get('terms_conditions')

if accepted_terms != 'accepted':
return 'Please accept the terms and conditions and try again!'

# HTML being returned as plain text
return f"""
Your order summary: <br>
Email: {users_email} <br>
Phone number: {users_phone} <br><br>
You ordered a {crust_type} crust pizza of size {pizza_size}-inch
with the following toppings: {', '.join(list_of_toppings)}
"""


# turn the server on for serving
if __name__ == "__main__":
app.run(debug=True, port=3000)
app.run(debug=True, port=3000)
8 changes: 8 additions & 0 deletions flaskPractice/templates/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<form action="/results" method="POST">
What's your favorite pizza flavor?
<input type="text" name="pizza_flavor">
<br>
What's your favorite crust type?
<input type="text" name="crust">
<input type="submit" value="submit pizza">
</form>
1 change: 1 addition & 0 deletions flaskPractice/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Welcome to your first website from the template</h1>
29 changes: 29 additions & 0 deletions flaskPractice/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def divide(numerator, denominator):
return numerator / denominator

#named parameter
answer = divide(denominator=6, numerator=12)
# print (answer)

# *args (for list )
def add_all_numbers(*args):
total = 0
for num in args:
total += num
return total

answer = add_all_numbers(1, 2, 3, 4, 5)


# **kwargs (for dictionary)

def print_user_attributes(**kwargs):
for key, value in kwargs.items():
print(key + ": "+str(value))

print_user_attributes(
first_name='Nathan',
last_name='Jeon',
age = 30
)

0 comments on commit 174ae9c

Please sign in to comment.