Code to clone and break reference:
git clone https://github.com/upperlinecode/flaskproject
cd flaskproject
rm -rf .gitCode to install Flask (only necessary once):
pip install flaskCode to configure your flask app (run once each time you open a new terminal):
export FLASK_APP=main.py
export FLASK_RUN_HOST=0.0.0.0
export FLASK_RUN_PORT=8080
export FLASK_DEBUG=1Code to run flask:
flask runIf you're developing in the cs50 IDE, ignore this next part.
If you're developing locally, you can sometimes save time on the environment variables, by installing the python-dotenv package, which automatically loads the settings we're currently setting with export:
pip install python-dotenvIf you're running this locally, you may want to run this program inside a virtual environment - that way changes to your Python configuration don't persist and impact other python programs on your machine. We've also beta tested virtual environments on Codenvy, where it seems to work intermittently - we kept track of some Codenvy tricks to make that easier.
To create a virtual environment (you only need to do this once), run this code in terminal:
python3 -m venv venvTo ENTER your virtual environment (you'll need to do this every time you open up a new terminal), run this code:
. venv/bin/activateTo EXIT your virtual environment (you'll want to do this if you decide to change projects - think of it like shutting this one down), you just need one word:
deactivateIf you're using a virtual environment like Codenvy, the virtual environment produces more problems than it solves, so consider skipping this step.
To start, the only package you need to run is flask for (hopefully) obvious reasons.
To install flask, run this code in terminal.
pip install flaskRemember, if you're using a virtual environment, these packages will only be installed IN the virtual environment (which is part of why we don't recommend it in cs50 where we won't need it - students will accidentally forget where they've configured different settings).
If your IDE throws errors on either of these commands saying that you aren't authorized, your account may not be authorized to install packages on the IDE you're using, so try adding the 'switch user and do' command ('sudo' for short):
pip install --user flaskThe settings will not be stored between sessions, so every time you open a new terminal, you'll need to run these commands, which are stored in the run-variables.md file for your convenience:
export FLASK_APP=main.py
export FLASK_RUN_HOST=0.0.0.0
export FLASK_RUN_PORT=8080
export FLASK_DEBUG=1After that you should be able to execute the flask run command normally.