File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed
Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change 2929
3030
3131def get_ip ():
32+ """Read the IP address from the current request."""
3233 try :
3334 return request .headers ["X-Real-IP" ]
3435 except KeyError :
@@ -37,24 +38,29 @@ def get_ip():
3738
3839@app .route ("/" )
3940def ip_html ():
41+ """Render a human-friendly homepage with the received remote IP information."""
4042 user_ip = get_ip ()
4143 return render_template ("index.html" , user_ip = user_ip )
4244
4345
4446@app .route ("/ip.json" )
4547@app .route ("/json" )
4648def ip_json ():
49+ """Return a JSON with the remote IP information."""
4750 return json .jsonify (ip = get_ip ())
4851
4952
5053@app .route ("/ip.txt" )
5154@app .route ("/plain" )
5255def ip_plain ():
56+ """Return only the remote IP."""
5357 return get_ip ()
5458
5559
5660@app .errorhandler (404 )
5761def page_not_found (error ):
62+ """On 404, just redirect to the homepage."""
63+ print (error )
5864 return ip_html (), 301
5965
6066
You can’t perform that action at this time.
0 commit comments