-
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
c4d1496
commit 174ae9c
Showing
4 changed files
with
79 additions
and
17 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 |
---|---|---|
@@ -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) |
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,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> |
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 @@ | ||
<h1>Welcome to your first website from the template</h1> |
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,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 | ||
) | ||
|