A minimal Weather app built using Flask and Bootstrap
See a live version deployed on heroku here
Clone the project
git clone https://github.com/vaylon-fernandes/flask_weather_app.git
Go to the project directory
cd flask_weather_app
Create a virtual enviroment. Read more
venv <environment name>
apt-get install python3-venv
On Linux:
source venv/bin/activate
On Windows:
venv\Scripts\activate
Install dependencies
pip install -r requirements.txt
In addition to the dependancies you wil have to create a Open Weather Map and get a API Key
. Read about how to get a 'API Key' in the open weather mao FAQ section here
- Firstly Generate a
Secret Key
. This is required by the Flask Sessions. Do read the section on How to generate good secret keys in the flask documentation under sessions here - Next export the secret key and API key to Enviroment Variables using one of the following commands based on your terminal Bash command
export SECRET_KEY=<your secret key>
export API_KEY=<your API key>
CMD command
set SECRET_KEY=<your secret key>
set API_KEY=<your API key>
Powershell command
$env:SECRET_KEY=<your secret key>
$env:API_KEY=<your API key>
The enviroment variables are then read using the os.environ object
To run the app, first export the FLASK_APP
variable, using one of the following commands based on your terminal
Bash command
export FLASK_APP=main
CMD command
set FLASK_APP=main
Powershell command
$env:FLASK_APP = "hello"
flask run
This creates a simple server, go to http://127.0.0.1:5000/
in your browser to view the site
To run the server in Debug mode, export the FLAK_ENV
variable befor running flask run
Bash command
export FLASK_ENV=development
CMD command
set FLASK_ENV=development
Powershell command
$env:FLASK_ENV="development"
Run command
flask run
Read more here: https://flask.palletsprojects.com/en/2.0.x/quickstart/#debug-mode
- There's a good explanation of this given in this repo
- Another good read on the topic is on the Real Python website
- Open Weather Map Current Weather Map API Docs - https://openweathermap.org/current
- Flask Docs - https://flask.palletsprojects.com/en/2.0.x/
- Bootstrap Docs - https://getbootstrap.com/docs/5.0/getting-started/introduction/