How to use flask to publish webservice that can be called by other machines

I set up a flask project using VS2015. The code is as follows:

views.py:


from datetime import datetime
from flask import render_template
from flask import Flask
from FlaskWebProject1 import app

@app.route("/")
@app.route("/home")
def home():
    return render_template(
        "index.html",
        title="Home Page"
    )

@app.route("/greeting/<surname>/<lastname>")
def greeting(surname,lastname):
    return ("Hello "+surname+" "+lastname)

runserver.py:

"""
This script runs the FlaskWebProject1 application using a development server.
"""

from os import environ
from FlaskWebProject1 import app

if __name__ == "__main__":
    HOST = environ.get("SERVER_HOST", "localhost")
    try:
        PORT = int(environ.get("SERVER_PORT", "5555"))
    except ValueError:
        PORT = 5555
    app.run(host = "0.0.0.0", port = 8081, debug = False)

according to flask"s official tutorial:

host0.0.0.0:Running on http://0.0.0.0:8081/
cmd ipconfig/all IP192.168.1.101IP
"IP" IP183.62.69.42IP
192.168.1.101:8081/greeting/a/b
183.62.69.42:8081/greeting/a/b
webservice

ipconfig:

Mar.06,2021

if it is accessed through the private network, 192.168.1.101:8081/greeting/a/b is fine.

if it is accessed by the external network, and the host is running in the landlord's own local area network, it may be more troublesome.
is supposed to require extranet ip and port mapping on the router (not done, not very clear)

so if the landlord wants to provide services that can be accessed by the public network, it is more convenient and stable to rent a cloud server.
when you buy a server, you will be assigned an extranet ip.

Menu