diff --git a/extension.py b/extension.py new file mode 100644 index 0000000..48151c7 --- /dev/null +++ b/extension.py @@ -0,0 +1,17 @@ +import os +from flask import Flask, render_template, request, url_for, redirect +from jinja2 import Environment, FileSystemLoader +# create the application object +app = Flask(__name__) +tpldir = os.path.dirname(os.path.abspath(__file__))+'/templates/' +env = Environment(loader=FileSystemLoader(tpldir), trim_blocks=True) + + +@app.route('/', methods=['GET', 'POST']) +def Jquerytest(): + return render_template('MP5.html') + + +# start the server with the 'run()' method +if __name__ == '__main__': + app.run(debug=True) diff --git a/flask_app.py b/flask_app.py index b03bdc6..2fb70ca 100644 --- a/flask_app.py +++ b/flask_app.py @@ -1,3 +1,39 @@ """ Put your Flask app code here. -""" \ No newline at end of file +""" +import os +from flask import Flask, render_template, request, url_for, redirect +from jinja2 import Environment, FileSystemLoader +# create the application object +app = Flask(__name__) +tpldir = os.path.dirname(os.path.abspath(__file__))+'/templates/' +env = Environment(loader=FileSystemLoader(tpldir), trim_blocks=True) + + +# route for handling the login page logic +@app.route('/', methods=['GET', 'POST']) +def login(): + error = None + if request.method == 'POST': + name = request.form.get('username') + age = request.form.get('age') + ninja = request.form.get('ninja') + if name and age and ninja: + output = env.get_template('postlogin.html').render( + ninja='Patrick Huston', age=age, name=name) + return output + else: + return redirect(url_for('error')) + return render_template('login.html') + + +@app.route('/error', methods=['GET', 'POST']) +def error(): + if request.method == 'POST': + return redirect(url_for('login')) + return render_template('error.html') + + +# start the server with the 'run()' method +if __name__ == '__main__': + app.run(debug=True) diff --git a/hello.py b/hello.py index 2420ed6..d242684 100644 --- a/hello.py +++ b/hello.py @@ -1,13 +1,23 @@ """ Simple "Hello, World" application using Flask """ - -from flask import Flask +from flask import Flask, render_template, request app = Flask(__name__) -@app.route('/') -def hello_world(): - return 'Hello World!' + +@app.route('/', methods=['POST', 'GET']) +def login(): + error = None + if request.method == 'POST': + if valid_login(request.form['firstname'], + request.form['lastname']): + return log_the_user_in(request.form['username']) + else: + error = 'Invalid username/password' + # the code below is executed if the request method + # was GET or the credentials were invalid + return render_template('WebAppTest.html', error=error) + if __name__ == '__main__': app.run() diff --git a/static/Jquery.js b/static/Jquery.js new file mode 100644 index 0000000..e473f80 --- /dev/null +++ b/static/Jquery.js @@ -0,0 +1,6 @@ +$(function() { + $("button").click(function() { + $("p").hide(); + }); + +}); diff --git a/templates/MP5.html b/templates/MP5.html new file mode 100644 index 0000000..0f4554c --- /dev/null +++ b/templates/MP5.html @@ -0,0 +1,75 @@ + + + + + + + + + + + +
+

This is my first custom website!

+
+

Click on me for some info!

+

I have learned a lot about both JQuery and CSS styling.

+ + +
+ +
+ +
+ +
+

please give me an A

+ + + + diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 0000000..e8ef34f --- /dev/null +++ b/templates/error.html @@ -0,0 +1,19 @@ + + + Login: + + + + +
+
+
+

You did not input all required information. Try again.

+ +
+ {% if error %} +

Error: {{ error }} + {% endif %} +

+ + diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..605c13e --- /dev/null +++ b/templates/login.html @@ -0,0 +1,29 @@ + + + + Login: + + + +

Please give me some basic information

+ + +
+
+
+

Your name:

+
+

Your age

+
+

Your favorite SoftDes Ninja

+

+ +
+ {% if error %} +

Error: {{ error }} {% endif %} +

+ + + diff --git a/templates/postlogin.html b/templates/postlogin.html new file mode 100644 index 0000000..4ca5423 --- /dev/null +++ b/templates/postlogin.html @@ -0,0 +1,18 @@ + + + Post Login: + + + +

Profile

+ +

Name: {{name}}

+

Age: {{age}}

+

Favorite Ninja: {{ninja}}

+ + {% if error %} +

Error: {{ error }} + {% endif %} + + +