This is a boilerplate repository for starting new exercises for Flask learners.
These instructions are a simplified version of the Flask installation instructions and quickstart. If you have any questions, feel free to reach out to me.
- Clone this repository using
git cloneandcdfrom your command line into the folder. - Make sure you have Python 3 installed. You can check this by seeing if the command
python3works in your command line. If you don't have Python 3 installed, follow these instructions - From the root of the repository, run the following command:
sh setup.sh. This is a file I've written to automate the initial setup of this application. It will start your app automatically, and you can go tolocalhost:5000in a web browser to view it. If you want detailed instructions on how this file works, go to "How setup.sh works" below. - Whenever you're about to work on your application, make sure to run
. venv/bin/activatefirst to start your virtual environment, then you can runflask runfrom the root of your repository.
- Python 3 comes with venv, a "virtual environment" to manage packages like
Flaskthat you'll need to run your application. When you first clone this repository, runpython3 -m venv venvfrom the root of the repository to create a virtual environment for your application. This will create a few folders and files related to venv, in avenvfolder. - Once you've set up a virtual environment, whenever you're about to work on your app, make sure to run
. venv/bin/activatefrom the root of the repository. You should then see(venv)prefixed in your command line to show that you're using the virtual environment. After you do this, you should be able to download packages and run your application. - Once you are using the virtual environment, make sure you install all the dependencies for this application by running
pip install -r requirements.txt(if you're using Python 3, you might need to usepip3instead ofpip. You only need to do this once and don't need to again when you want to run your application. - Once you have
Flaskproperly installed, make sure you set your environment variables so Flask knows what file to start with. In this repository, the app starts with the fileapp.py. If you renameapp.pyor want to use a different file as the entrypoint, you'll have to runexport FLASK_APP={FILENAME}and replace{FILENAME}with the correct filename to make sure the app runs. - Once you have everything setup, you should be able to run
flask runand your server should start listening. Go to a browser atlocalhost:5000and you should see your app running.