Skip to content

Commit 77849a2

Browse files
committed
add POST request method for main page for search box
1 parent a381250 commit 77849a2

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

server/app.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,32 @@ def whatIsMyIp():
2222
return jsonify({"ip":request.remote_addr})
2323

2424

25-
@app.route("/" , methods = ["GET"])
25+
@app.route("/" , methods = ["GET" , "POST"])
2626
def whatismyip():
2727
loger.loger(request.remote_addr , request.user_agent , request.base_url)
2828

29-
infq = checkIpInfo((request.remote_addr))
30-
return render_template("home.html" , ip = request.remote_addr ,country = infq["country"] ,
31-
city = infq["city"] , isp =infq["isp"])
29+
if request.method == "POST" :
30+
rqIp = request.form.get("ip")
31+
32+
infq = checkIpInfo((rqIp))
33+
try :
34+
country , city , isp = infq["country"] , infq["city"] , infq["isp"]
35+
except Exception :
36+
country , city , isp = None , None , None
37+
38+
39+
return render_template("home.html" , ip = rqIp ,country = country ,
40+
city = city , isp = isp)
41+
42+
else :
43+
infq = checkIpInfo((request.remote_addr))
44+
try :
45+
country , city , isp = infq["country"] , infq["city"] , infq["isp"]
46+
except Exception :
47+
country , city , isp = None , None , None
48+
49+
return render_template("home.html" , ip = request.remote_addr ,country = country ,
50+
city = city , isp = isp)
3251

3352

3453

0 commit comments

Comments
 (0)