I want to make a detector of whether a user is browsing my site
Whenever someone goes to the main route, you could change the main value, or send a request to another endpoint where the value gets changed
Can you give an example code for me?
assuming we have defined a flask app and replit db above
@app.route(“/“) def index(): value = db[‘Views’] newvalue = value + 1 del db[‘Views’] db[‘Views’] = newvalue
I don’t think you need a database for this.
I would suggest setting up a before request method, which checks the session and then adds 1 to a counter if someone’s currently on your page.
Store the last time that they made a request, and then have a loop threaded which checks how long it’s been since each user made a request and theb remove them from your list of current users if it’s been to long.
The other, possibly simpler, option is to setup a websocket on every page and then it’s really easy to count how many are connected.
@CodingCactus but i don’t know how to do it
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.