Flask Cheatsheet

Simple Flask example

+

from flask import Flask, render_template
app = Flask(__name__)

months = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
              'August', 'September', 'October', 'November', 'December']

@app.route('/')
def index():
    return render_template('index.html', city='Portland, OR', months=months)


if __name__ == '__main__':
    app.run(debug=True)

Install a python package

pip install ansible

Install a specific package version

pip install ansible==2.7.8

Uninstall a python package

pip uninstall ansible

See what versions are available (use illegal version string!)

pip install ansible==foobar

Upgrade a package

pip install --upgrade ansible or pip install ansible -U

Package Management

List installed packages

pip list

List installed packages

pip list --outdated

Upgrade installed package

pip install --upgrade ansible or -U

Capture installed packages

pip freeze > requirements.txt

Install a dependencies file

pip freeze -r requirements.txt

Deleting secondary dependencies, not so easy, hacky solution? :(

  1. Capture your dependencies pip freeze > requirements.ym;

  2. Edit requirements.yml removing unwanted dependencies

  3. Make a new virtualenv

  4. Install your new dependencies list pip install -r requirements.yml

Tony Kay avatar
About Tony Kay
Team lead for Automation and Management in Red Hat's GPTE DevOps and Automation team. Working globally, I focus primarily on Hybrid Cloud Automation with Ansible. About 2/3rds of my time is automating production cloud deployments and developing both code and training content. I also deliver Automation training globally to both Red Hat and Partner Consultants and Architects on cloud infrastructure using Ansible and on OpenShift/Kubernetes.
comments powered by Disqus