diff --git a/hello.py b/hello.py index 2420ed6..75d3ee6 100644 --- a/hello.py +++ b/hello.py @@ -2,12 +2,34 @@ Simple "Hello, World" application using Flask """ -from flask import Flask +from flask import Flask, render_template, request, url_for app = Flask(__name__) +'''with app.test_request_context('/form', method='POST'): + assert request.path == '/form' + assert request.method == 'POST' +''' @app.route('/') def hello_world(): - return 'Hello World!' + return render_template('index.html') + +@app.route('/login') +def login(): + return render_template('action.html') + +@app.route('/form', methods=['POST']) +def form(): + name = request.form['name'] + age = request.form['age'] + ninja = request.form['ninja'] + if name == '' or age == '' or ninja == '': + return render_template('error.html', error="At least one of the fields was empty!") + else: + try: + int(age) + except ValueError: + return render_template('error.html', error="Age must be an integer") + return render_template('form.html', name=name, age=age, ninja='Patrick Huston') if __name__ == '__main__': - app.run() + app.run() \ No newline at end of file diff --git a/templates/action.html b/templates/action.html new file mode 100644 index 0000000..56a0dc9 --- /dev/null +++ b/templates/action.html @@ -0,0 +1,15 @@ + + Form +

Login

+
+
+ +
+ +
+ +
+ +
+
+ \ No newline at end of file diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 0000000..5ef0e3e --- /dev/null +++ b/templates/error.html @@ -0,0 +1,13 @@ + + + + + Error + + + +

Error

+

{{ error }}

+

login

+ + \ No newline at end of file diff --git a/templates/form.html b/templates/form.html new file mode 100644 index 0000000..3e57ef8 --- /dev/null +++ b/templates/form.html @@ -0,0 +1,11 @@ + + + + Hello from Flask + + +

Hello {{ name }}!

+

Your age is {{ age }}.

+

Your favorite Sofdes ninja is {{ ninja }}.

+ + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..3d3b59e --- /dev/null +++ b/templates/index.html @@ -0,0 +1,13 @@ + + + + + A Small Hello + + + +

Hi

+

This is very minimal "hello world" HTML document.

+

login

+ + \ No newline at end of file