Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python + Flask + Redis - Page Hit Counter
#!/usr/bin/python
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host="172.17.0.2", port=6379)
@app.route("/", methods=["GET"])
@app.route("/index", methods=["GET", "POST"])
def index():
""" Return the homepage counter """
counter = redis.incr("hits")
return render_template(
"index.html",
counter=counter
)
if __name__ == "__main__":
app.run(
host="0.0.0.0",
port=8000,
debug=True
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.