Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions hello.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
"""
Simple "Hello, World" application using Flask
"""

from flask import Flask
from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__)

@app.route('/')
def hello_world():
return 'Hello World!'
#@ is a decorator; the next part is executed --> app.route('/' hello_world)
@app.route('/') #'/' is the index of a page; tells Flask to run this function
def hello(): #for an incoming requests (GET)
return render_template('index.html')

@app.route('/login',methods=['POST','GET'])
def login():
if request.method == 'POST':
name = request.form['Name']
age = request.form['Age']
ninja = request.form['Favorite NINJA']
if name == '' or age == '' or ninja == '':
return render_template('error.html')
return render_template('login.html',name=name,age=age,ninja=ninja)
else:
return render_template('error.html')

@app.route('/index',methods=['POST','GET'])
def index():
if request.method == 'POST':
return render_template('index.html')

if __name__ == '__main__':
app.run()
app.debug = True
app.run(
host = "127.0.0.1",
port = int("7000")
)
15 changes: 15 additions & 0 deletions templates/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>
Uh Oh
</title>
</head>
<body>
<h1>You done f*cked up.</h1>
<p>Seriously, you couldn't fill in three boxes? Give it another try.</p>
<form action="/index" method="POST">
<input type="submit" value="Back">
</form>
</body>
</html>
21 changes: 21 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>
Welcome
</title>
</head>
<body>
<h1>Hey there!</h1>
<p>Please fill out the information below. That's it.</p>
<form action="/login" method="POST">
Name:<br>
<input type="text" name="Name"><br>
Age:<br>
<input type="text" name="Age"><br>
Favorite NINJA:<br>
<input type="text" name="Favorite NINJA">
<input type="submit" value="Submit">
</form >
</body>
</html>
13 changes: 13 additions & 0 deletions templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<title>
Hiya
</title>
</head>
<body>
<h1>Hello {{ name }}!</h1>
<p>Wow, you don't look bad for {{ age }}. </p>
<p>Yeah, I agree. {{ ninja }} is awesome -- way better than that Patrick Huston kid. </p>
</body>
</html>