In [1]:
# Code attribution: Yiyin Shen, Tyler Caraza-Harter
# Imports
from flask import Flask, request, redirect, jsonify, Response
import matplotlib.pyplot as plt
import time
import pandas
In [ ]:
# Build a webpage that keeps track of visitors
app = Flask("app")
visitor = 0
visitors = []
@app.route("/")
def index():
return redirect("visit")
@app.route("/visit")
def home():
global visitor, visitors
visitor = visitor + 1
visitors.append([visitor, "-", request.remote_addr])
return "Hello, visitor " + str(visitor)
@app.route("/visit/<x>")
def hello(x):
global visitor, visitors
visitor = visitor + 1
visitors.append([visitor, x, request.remote_addr])
return "Hello, " + x
@app.route("/visitors")
def display():
df = pandas.DataFrame(visitors, columns = ["#", "Name", "IP"])
return df.to_html()
app.run(host = "0.0.0.0", debug = False, threaded = False)
* Serving Flask app 'app' * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on all addresses (0.0.0.0) * Running on http://127.0.0.1:5000 * Running on http://192.168.1.87:5000 Press CTRL+C to quit