Answer the question
In order to leave comments, you need to log in
Python How to implement a local server hit counter?
In order to study python, the task was to write a site visit counter.
I set up a local server on flask and just when someone requests the index.html page - the counter +=1 and writes it to a *.txt file on my PC.
But now the task is to display statistics on the site itself.
There is an idea that there should be a button in the html page, which is like a gif or just a picture up to 10x10 in size, and when you click it, you can see statistics about the number of connections.
How to implement it?
How can I transfer the data that I write in txt to html?
Can I python directly in the html page?
Answer the question
In order to leave comments, you need to log in
As a solution: write a get method on flask that will read your file and return the number stored there. On the index.html page, use js to implement a call to the method once every k seconds (or when your button is pressed), and display it in any place convenient for you. You can't write python code in an html page, but you can use jinja2 template design techniques.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question