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
24 changes: 23 additions & 1 deletion flask_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
"""
Put your Flask app code here.
"""
"""

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


@app.route('/')
def welcome():
return render_template('index.html')


@app.route('/login', methods=['GET', 'POST'])
def login():
if request.form['name'] and request.form['age'] and request.form['faveninja']:
name = request.form['name']
age = request.form['age']
return render_template('profile.html', name=name, age=age)
else:
return render_template('error.html')


if __name__ == '__main__':
app.run()
9 changes: 7 additions & 2 deletions hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
Simple "Hello, World" application using Flask
"""

from flask import Flask
from flask import Flask, render_template
app = Flask(__name__)

@app.route('/')
def hello_world():
return 'Hello World!'
return render_template('index_.html')

@app.route('/hello')
@app.route('/hello/<name>')
def hello(name=None):
return render_template('hello.html', name=name)

if __name__ == '__main__':
app.run()
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>
Error
</title>
</head>
<body>
<h1>Error!</h1>
<p>There was something wrong with your entry. Please try again.</p>
<form action="/" method="GET">
<input type="submit" value="Go Back">
</form>
</body>
</html>
7 changes: 7 additions & 0 deletions templates/hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<title>Hello from Flask</title>
{% if name %}
<h1>Hello {{ name }}!</h1>
{% else %}
<h1>Hello World!</h1>
{% endif %}
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>
Input Form
</title>
</head>
<body>
<h1>Hello!</h1>
<p>Please fill out the form below.</p>
<form action="/login" method="POST">
Name:<br>
<input type="text" name="name"><br><br>
Age:<br>
<input type="text" name="age"><br><br>
Favorite SoftDes Ninja:<br>
<input type="text" name="faveninja"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
12 changes: 12 additions & 0 deletions templates/index_.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>
A Small Hello
</title>
</head>
<body>
<h1>Hi</h1>
<p>This is very minimal "hello world" HTML document.</p>
</body>
</html>
17 changes: 17 additions & 0 deletions templates/profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>
Profile
</title>
</head>
<body>
<h1>Hello, {{name}}!</h1>
<p>
Here is your profile:<br><br>
Name: {{name}}<br>
Age: {{age}}<br>
Favorite SoftDes Ninja: Patrick Huston
</p>
</body>
</html>