I have one flask application script as given below :
我有一个烧瓶应用程序脚本,如下所示:
from flask import Flask
app = Flask(__name__)
@app.route("/<string:job_id>")
def main(job_id):
return "Welcome!. This is Flask Test Part 1"
if __name__ == "__main__":
job_id = 1234
app.run(host= '0.0.0.0')
I have another flask application script as below :
我有另一个烧瓶应用程序脚本如下:
from flask import Flask
app = Flask(__name__)
@app.route("/<string:ID>")
def main(ID):
return "Welcome!. This is Flask Test Part 2"
if __name__ == "__main__":
ID = 5678
app.run(host= '0.0.0.0')
The only difference between both the scripts is the argument name and its value. Now my question is assume that I am executing the first script. So I will get something like
两个脚本之间的唯一区别是参数名称及其值。现在我的问题是假设我正在执行第一个脚本。所以我会得到类似的东西
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
When I execute http://127.0.0.1:5000/1234 in my browser I am able to see
当我在浏览器中执行http://127.0.0.1:5000/1234时,我能够看到
"Welcome!. This is Flask Test Part 1"
“欢迎!这是Flask Test Part 1”
Now with this server active, I am executing the second script. So again I get
现在这个服务器处于活动状态,我正在执行第二个脚本。所以我再次得到
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
But when I execute http://127.0.0.1:5000/5678 in my browser I am able to see
但是当我在浏览器中执行http://127.0.0.1:5000/5678时,我能够看到
"Welcome!. This is Flask Test Part 1"
“欢迎!这是Flask Test Part 1”
instead of
"Welcome!. This is Flask Test Part 2"
“欢迎!这是Flask Test Part 2”
I don't understand where I am doing mistake. Any inputs or alterations will be helpful
我不明白我在哪里做错了。任何输入或更改都会有所帮助
1 个解决方案
#1
3
Flask development server by default listen on port 5000
. So when you run a Flask app without port number it will run on 5000
.
Flask开发服务器默认侦听端口5000.因此,当您运行没有端口号的Flask应用程序时,它将运行在5000上。
You can run number of Flask app on the same machine but with different port number. Lets say your scripts names are script1.py
and script2.py
:
您可以在同一台计算机上运行多个Flask应用程序,但使用不同的端口号。让我们说你的脚本名称是script1.py和script2.py:
$ export FLASK_APP=script1.py
$ flask run --host 0.0.0.0 --port 5000
Open up a new terminal
打开一个新的终端
$ export FLASK_APP=script2.py
$ flask run --host 0.0.0.0 --port 5001
#1
3
Flask development server by default listen on port 5000
. So when you run a Flask app without port number it will run on 5000
.
Flask开发服务器默认侦听端口5000.因此,当您运行没有端口号的Flask应用程序时,它将运行在5000上。
You can run number of Flask app on the same machine but with different port number. Lets say your scripts names are script1.py
and script2.py
:
您可以在同一台计算机上运行多个Flask应用程序,但使用不同的端口号。让我们说你的脚本名称是script1.py和script2.py:
$ export FLASK_APP=script1.py
$ flask run --host 0.0.0.0 --port 5000
Open up a new terminal
打开一个新的终端
$ export FLASK_APP=script2.py
$ flask run --host 0.0.0.0 --port 5001