forked from dominict/pythonteachingcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBen_Reed_script1.py
More file actions
34 lines (28 loc) · 1.17 KB
/
Ben_Reed_script1.py
File metadata and controls
34 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'''
This is a basic web page running with Flask.
'''
from flask import Flask, render_template, request
#This is the Flask object, we are creating an instance of the Flask class and storing it in the variable app
#__name__ is a special variable in Python that is the name of the module, which is this file's name without the .py extension
app=Flask(__name__)
#This is a decorator, it is a function that takes a function as a parameter!
#A decorator is a function that wraps another function
#This decorator is saying that when someone goes to the URL /greet, run the greet function
@app.route('/greet', methods=['POST'])
def greet():
inputName = request.form['myName']
ip = request.remote_addr
#write data to file or to DB
inputName = inputName.upper()+" hi! Visiting from " + str(ip)
return render_template("home.html",myName=inputName)
@app.route('/')
def home():
return render_template("home.html",myName="Type your name in the box and click submit!")
@app.route('/about/')
def about():
return render_template("about.html")
@app.route('/benjamin/')
def benjamin():
return render_template("benjamin.html")
if __name__=="__main__":
app.run(debug=True)