How to Setup a New Flask App on a Mac

This blog post is brought to you by the developer of BitBudget. BitBudget is an automated budgeting app for Android and iOS which syncs with your bank account and helps you avoid overspending. If you’d like to quit living paycheck-to-paycheck and get a better handle on your finances, download it today! https://bitbudget.io

Welcome back internet friend!

Quick post here tonight on how to setup a new flask app for development on a Mac. In the past I’ve done all of my Python/Flask development on a Windows desktop computer, but since I’m now doing all of my development on a Macbook Pro, I wanted to write another little quickstart reference for myself or anyone else out there on the internet to get up and running with Python and Flask on a Mac (assumes you’ve already installed Python 3, if you haven’t, please visit https://python.org):

First, create a directory for your new Flask project

$ mkdir MyNewFlaskApp

Navigate to your newly created directory

$ cd MyNewFlaskApp

Create your virtual environment

$ python3 -m venv venv

Activate the virtual environment

$ source venv/bin/activate

Make sure Flask is installed

(venv) $ pip3 install Flask

Now write the actual python code for your flask application. We’ll call our python script my_new_flask_app.py. Save this script in your MyNewFlaskApp directory.

from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'hello, world'

Set the FLASK_APP system variable

(venv) $ export FLASK_APP=my_new_flask_app.py

Run Flask

(venv) $ flask run

Visit http://127.0.0.1:5000 to see your app in action

 

topherPedersen