深度阅读

How to specify a port when starting a Flask application

作者
作者
2023年08月22日
更新时间
11.9 分钟
阅读时间
0
阅读量

To specify a port when starting a Flask application, you can use the run() method and pass the port parameter with the desired port number. For example, if you want to start the application on port 5000, you can do the following:

from flask import Flask

app = Flask(__name__)

# Define your routes and views here

if __name__ == '__main__':
    app.run(port=5000)

This will start the Flask application on port 5000. You can replace 5000 with any other port number that you prefer.

To specify a port for a Flask application when starting it from the command line

To specify a port for a Flask application when starting it from the command line, you can use the flask run command and pass the -p or --port parameter followed by the desired port number. Here’s an example of how to start a Flask application on port 5000 from the command line:

export FLASK_APP=yourapp.py
flask run --port=5000

Replace “yourapp.py” with the actual filename of your Flask application. This will start the Flask application on port 5000. You can use a different port number if you prefer.

相关标签

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。