I am using flask_view_counter
to track all the views. It saves to the database properly, however, I can not get all the views inside the program. I have tried to do it using SQLAlchemy, but mostly it uses models to find information from database.
Here is the example of code:
main.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Views</title>
</head>
<body>
<h1>All the views: {{ my_views }}</h1>
</body>
</html>
app.py
from flask import Flask, render_template
from flask_view_counter import ViewCounter
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///site.db'
views = ViewCounter(app, db)
@app.route('/')
@views.count
def mai():
my_views = None # how to get it???
return render_template('main.html', my_views=my_views)
if __name__ == "__main__":
app.run(debug=True)
If there is another way to make a view counter using python or javascript, I would like to see it.