-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
30 lines (24 loc) · 737 Bytes
/
server.py
File metadata and controls
30 lines (24 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask import Flask, render_template, request, redirect, session
app = Flask(__name__)
app.secret_key = "keep this secret"
@app.get("/")
def counting():
session['counter'] +=1
if session['counter'] ==0:
count_x = (f'You have visisted {session['counter']} times!!')
print(count_x)
else:
count_x = (f'You have visited {session['counter']} time!!')
print(count_x)
return render_template("index.html", count_x=count_x)
@app.post('/increment_by')
def increment_x():
session['counter'] += 1
return redirect('/')
@app.post('/clear')
def clear_count():
session.clear()
session['counter'] = 0
return redirect('/')
if __name__ == "__main__":
app.run(debug=True)