Flask 101
Installation:
Install Python:
- Make sure Python is installed on your system. You can download it from python.org or use your system's package manager.
Install Flask:
Open a terminal or command prompt.
Run the following command to install Flask using pip:
pip install Flask
Create a Flask App:
Create a Directory:
Create a new directory for your Flask project.
mkdir my_flask_app cd my_flask_app
- aaaaaa
Create a Virtual Environment (Optional):
(Optional but recommended) Create a virtual environment to isolate your project dependencies:
python -m venv venv
Activate the virtual environment:
source venv/bin/activate
Create a Flask App:
Create a new file, e.g.,
app.py, and open it in a text editor.from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return 'Hello, World!' if __name__ == '__main__': app.run(debug=True)
Run the Flask App:
In the terminal, run the following command to start the Flask development server:
python app.py
Access the app in your web browser at http://127.0.0.1:5000/.
Optional: Specify Port (Advanced):
If you want to use a different port, you can specify it when running the app:
python app.py --port=8080
Access the app at http://127.0.0.1:8080/.
Cleanup:
Deactivate Virtual Environment (if used):
If you used a virtual environment, deactivate it:
deactivate

Comments
Post a Comment