diff --git a/flask_app.py b/flask_app.py index b03bdc6..b2d74eb 100644 --- a/flask_app.py +++ b/flask_app.py @@ -1,3 +1,25 @@ """ Put your Flask app code here. -""" \ No newline at end of file +""" + +from flask import Flask, render_template, request +app = Flask(__name__) + + +@app.route('/') +def welcome(): + return render_template('index.html') + + +@app.route('/login', methods=['GET', 'POST']) +def login(): + if request.form['name'] and request.form['age'] and request.form['faveninja']: + name = request.form['name'] + age = request.form['age'] + return render_template('profile.html', name=name, age=age) + else: + return render_template('error.html') + + +if __name__ == '__main__': + app.run() diff --git a/hello.py b/hello.py index 2420ed6..3338b06 100644 --- a/hello.py +++ b/hello.py @@ -2,12 +2,17 @@ Simple "Hello, World" application using Flask """ -from flask import Flask +from flask import Flask, render_template app = Flask(__name__) @app.route('/') def hello_world(): - return 'Hello World!' + return render_template('index_.html') + +@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/error.html b/templates/error.html new file mode 100644 index 0000000..6591010 --- /dev/null +++ b/templates/error.html @@ -0,0 +1,15 @@ + + + + + Error + + + +

Error!

+

There was something wrong with your entry. Please try again.

+
+ +
+ + 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..5ca6cb7 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,21 @@ + + + + + Input Form + + + +

Hello!

+

Please fill out the form below.

+
+ Name:
+

+ Age:
+

+ Favorite SoftDes Ninja:
+

+ +
+ + 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/profile.html b/templates/profile.html new file mode 100644 index 0000000..c206494 --- /dev/null +++ b/templates/profile.html @@ -0,0 +1,17 @@ + + + + + Profile + + + +

Hello, {{name}}!

+

+ Here is your profile:

+ Name: {{name}}
+ Age: {{age}}
+ Favorite SoftDes Ninja: Patrick Huston +

+ +