diff --git a/flask_app.py b/flask_app.py index b03bdc6..3945054 100644 --- a/flask_app.py +++ b/flask_app.py @@ -1,3 +1,41 @@ """ Put your Flask app code here. -""" \ No newline at end of file +""" +from flask import Flask, render_template, request + +app = Flask(__name__) + +@app.route('/login', methods=['GET', 'POST']) +def login(): + error = None + if request.form['name'] and request.form['age'] and request.form['ninja']: # if all inputs are given + name = request.form['name'] + age = request.form['age'] + ninja = request.form['ninja'] + if check_exist(ninja): # if NINJA choice valid + return render_template('profile.html', name = name, age = age) + else: # redirect to hello page if credentials invalid + error = 'Invalid Entry' + return render_template('profile.html',name = name, age = age, error=error) + else: + return ''' +

Error: Did not include all required info !

+ +
+ +
+ ''' + +def check_exist(ninja): + ninjas = ['Emily', 'Duncan', 'Hannah', 'Matt', 'Seungin', 'Tony'] + if ninja in ninjas: + return True + else: + return False + +@app.route('/') +def main(): + return render_template('hello.html') + +if __name__ == '__main__': + app.run() diff --git a/hello.py b/hello.py index 2420ed6..4b490c4 100644 --- a/hello.py +++ b/hello.py @@ -3,11 +3,35 @@ """ from flask import Flask +from flask import render_template + app = Flask(__name__) -@app.route('/') -def hello_world(): - return 'Hello World!' +def login(): + if request.method == 'POST': + check_exist() + else: + show_the_login_form() + +@app.route('/play') +@app.route('/hello//') +def hello(name=None): + return render_template('hello.html', name = name) + +@app.route('/user/') +def show_user_profile(username): + # show the user profile for that user + return 'User %s' % username + +@app.route('/post/') +def show_post(post_id): + # show the post with the given id, the id is an integer + return 'Post %d' % post_id +def check_exist(): + pass + +def show_the_login_form(): + pass if __name__ == '__main__': app.run() diff --git a/index b/index new file mode 100644 index 0000000..751c2e4 --- /dev/null +++ b/index @@ -0,0 +1,12 @@ + + + + + A Small Hello + + + +

Hi

+

This is very minimal "hello world" HTML document.

+ + diff --git a/templates/hello.html b/templates/hello.html new file mode 100644 index 0000000..fa1e9bf --- /dev/null +++ b/templates/hello.html @@ -0,0 +1,16 @@ + + + + Hello from Flask +

Hello World!

+ + + +
+ 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..fd0217d --- /dev/null +++ b/templates/profile.html @@ -0,0 +1,20 @@ + + + + Flask +

Your Profile

+ + + + {% if error %} +

Error: {{ error }}!

+ {% endif %} + +

Name: {{name}}

+

Age: {{age}}

+

Favorite NINJA: Patrick Huston

+ +
+ +
+