Python flask code to get the user's IP address

Source: Internet
Author: User
Tags html page

Python flask framework to get the user's IP address sample code, the following code contains HTML page and Python code, very detailed, if you are using flask, you can also learn the most basic flask use methods.

From flask import flask, render_template, request
# Initialize The Flask application
App = Flask (__name__)
# Default route, print user ' s IP
@app. Route ('/')
def index ():
IP = request.remote_addr
Return render_template (' index.html ', USER_IP=IP)
if __name__ = = ' __main__ ':
App.run (
Host= "0.0.0.0",
Port=int ("80")
)

HTML Template Code

<! DOCTYPE html>
<link href= "//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"
rel= "stylesheet" >
<body>
<div class= "Container" >
<div class= "Header" >

</div>
<div>
IP address is: <strong>{{user_ip}}</strong>
<div class= "Header" >

</div>
<pre>
From flask import flask, render_template, request
# Initialize The Flask application
App = Flask (__name__)
# Default route, print user ' s IP, http://www.111cn.net
@app. Route ('/')
def index ():
IP = request.remote_addr
Return render_template (' index.html ', USER_IP=IP)
</pre>
</div>
</div>
</body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.