From 3fa9ee98c47c0588722cfc2da5b6695e082eab66 Mon Sep 17 00:00:00 2001 From: William Derksen Date: Sat, 29 Apr 2017 02:40:06 -0400 Subject: [PATCH 1/2] Flask Toolbox Complete --- flask_app.py | 39 ++++++++++++++++++++++++++++++++++++++- hello.py | 2 +- multipage.py | 16 ++++++++++++++++ templates/form.html | 27 +++++++++++++++++++++++++++ templates/hello.html | 7 +++++++ templates/index.html | 12 ++++++++++++ templates/success.html | 13 +++++++++++++ 7 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 multipage.py create mode 100644 templates/form.html create mode 100644 templates/hello.html create mode 100644 templates/index.html create mode 100644 templates/success.html diff --git a/flask_app.py b/flask_app.py index b03bdc6..e3b810d 100644 --- a/flask_app.py +++ b/flask_app.py @@ -1,3 +1,40 @@ """ Put your Flask app code here. -""" \ No newline at end of file +""" +from flask import Flask +from flask import render_template +from flask import request + +app = Flask(__name__) + +#@app.route('/') +#def hello_world(): +# return render_template('form.html') + +def valid_login(name, age): + valid_name = 'william' + valid_age = '18' + if name == valid_name and age == valid_age: + return True + return False + +def log_the_user_in(name, age): + return render_template('success.html', name=name, age=age, ninja='Patrick Huston') + +@app.route('/', methods=['GET', 'POST']) +def form(): + error = None + if request.method == 'POST': + if valid_login(request.form['name'], + request.form['age']): + return log_the_user_in(request.form['name'], + request.form['age']) + else: + error = 'Invalid username/password' + # the code below is executed if the request method + # was GET or the credentials were invalid + return render_template('form.html', error=error) + + +if __name__ == '__main__': + app.run() diff --git a/hello.py b/hello.py index 2420ed6..6a937a4 100644 --- a/hello.py +++ b/hello.py @@ -7,7 +7,7 @@ @app.route('/') def hello_world(): - return 'Hello World!' + return "I'm Mr. MeeSeeks! Look at me!" if __name__ == '__main__': app.run() diff --git a/multipage.py b/multipage.py new file mode 100644 index 0000000..10e3af7 --- /dev/null +++ b/multipage.py @@ -0,0 +1,16 @@ +from flask import Flask +from flask import render_template +app = Flask(__name__) + +@app.route('/') +def index(): + return 'Index Page' + + +@app.route('/hello/') +@app.route('/hello/') +def hello(name=None): + return render_template('hello.html', name=name) + +if __name__ == '__main__': + app.run() diff --git a/templates/form.html b/templates/form.html new file mode 100644 index 0000000..cfd10cb --- /dev/null +++ b/templates/form.html @@ -0,0 +1,27 @@ + + + + Html Form + + + +

Login Form

+ {% if error %} +

{{ error }}

+ {% else %} +

Welcome to the Site!

+ {% endif %} +
+
+ Personal information Verification + Name:
+
+ Age:
+
+ Favorite SoftDes Ninja:
+
+ +
+
+ + diff --git a/templates/hello.html b/templates/hello.html new file mode 100644 index 0000000..7e9ee80 --- /dev/null +++ b/templates/hello.html @@ -0,0 +1,7 @@ + +Hello from Flask +{% if name %} +

Hello {{ name }}!

+{% else %} +

Hello World!

+{% endif %} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..751c2e4 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,12 @@ + + + + + A Small Hello + + + +

Hi

+

This is very minimal "hello world" HTML document.

+ + diff --git a/templates/success.html b/templates/success.html new file mode 100644 index 0000000..80e2d0e --- /dev/null +++ b/templates/success.html @@ -0,0 +1,13 @@ + + + + {{ name }}'s Account! + + + +

Welcome {{ name }}!

+

Your age, {{ age }}, and favorite Ninja, {{ ninja }} is sensitive information.

+ But It's Safe With Us. +

+ + From 01b66ce78fa959cd9453b9fd8fb49b01ba79069b Mon Sep 17 00:00:00 2001 From: William Derksen Date: Sat, 29 Apr 2017 03:01:45 -0400 Subject: [PATCH 2/2] added spunk to website --- templates/success.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/success.html b/templates/success.html index 80e2d0e..eb404f7 100644 --- a/templates/success.html +++ b/templates/success.html @@ -6,8 +6,8 @@

Welcome {{ name }}!

-

Your age, {{ age }}, and favorite Ninja, {{ ninja }} is sensitive information.

- But It's Safe With Us. +

Your age ({{ age }}) and favorite Ninja ({{ ninja }}) are sensitive pieces of information information.

+ But sensitive information is always safe in the circle.