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 @@ + +
{{ error }}
+This is very minimal "hello world" HTML document.
+