flask run on ip and port
Open a terminal window.
Navigate to the directory where your Flask application is located using the 'cd' command.
Set the FLASK_APP environment variable to the name of your Flask application file:
export FLASK_APP=your_app_name.py
Replace "your_app_name.py" with the actual name of your Flask application file.
- (Optional) Set the FLASK_ENV environment variable to "development" if you want to run the application in development mode:
export FLASK_ENV=development
This step is optional, and you can skip it if you want to run the application in the default production mode.
- Run the Flask application using the 'flask run' command. You can specify the host and port using the '--host' and '--port' options. For example, to run the application on IP address 127.0.0.1 (localhost) and port 5000, use the following command:
flask run --host=127.0.0.1 --port=5000
Replace the IP address and port number with your desired values.
Access your Flask application in a web browser using the specified IP address and port. In this example, you would navigate to http://127.0.0.1:5000/.
To stop the Flask application, press 'Ctrl + C' in the terminal window.
Note: Make sure to replace placeholder values such as "your_app_name.py," IP address, and port number with your actual application file name, desired IP address, and port.