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
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: python3 flask_app.py
49 changes: 49 additions & 0 deletions flask_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Put your Flask app code here.
"""

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


@app.route('/return', methods=['POST', 'GET'])
def hello_world():
print('in method')
error = None
if request.method == 'POST':
if(request.form['Name'] != '' and request.form['Age'] != '' and request.form['Favorite Softdes Ninja'] != ''):
name = request.form['Name']
age = request.form['Name']
else:
error = 'Input Required'

# error = 'Invalid username/password'
# if request.method == 'GET':
name = request.form['Name']
age = request.form['Age']
print(name)
print(age)
# the code below is executed if the request method
# was GET or the credentials were invalid
return render_template('return.html', name=name, age=age, error=error)


@app.route('/ajax', methods=['GET'])
def changeConent():
print('this was accessed')
return 'This is Ajax Request Respose from the Server. Sent without reloading the page'


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



if __name__ == '__main__':
HOST = '0.0.0.0' if 'PORT' in os.environ else '127.0.0.1'
PORT = int(os.environ.get('PORT', 5000))
app.run(host=HOST, port=PORT)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.6.1
16 changes: 16 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<title>Hello from Nick</title>
<h1>Hello !</h1>

<form action="/return" method="post">
<fieldset>
<legend>Personal information:</legend>
Name:<br>
<input type="text" name="Name"><br>
Age:<br>
<input type="text" name="Age"><br>
Favorite SoftDes Ninja:<br>
<input type="text" name="Favorite Softdes Ninja"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
32 changes: 32 additions & 0 deletions templates/return.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!doctype html>
<title>Hello from Nick</title>
{% if not error %}
<h1>Hello {{name}}!</h1>
<h1>Age: {{age}}</h1>
<h1>Favorite SoftDes Ninja: Patrick Hutson</h1>
{% else %}
<h1>{{error}}</h1>
{% endif %}

<body>

<div id="demo">
<h1>Look how dynamic this page is!</h1>
<button type="button" onclick="loadDoc()">Click This</button>
</div>

<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "ajax", true);
xhttp.send();
}

</script>

</body>