Flask Tutorial - SeoulSKY/safe-zone-system GitHub Wiki

Flask Tutorial

Installation

  • The installation guide for flask can be found here:
  • It's recommended that development be done within a virtual environment so when the app is deployed any library dependencies are included with the project rather than just existing on a local machine. Flask is very bare bones so many dependencies are needed.

Basics

@app.route('/product/<name>')
def get_product(name):
  return "The product is " + str(name)

html pages can be returned with the render_template library as well.

from flask import render_template

@app.route('/hello/')
@app.route('/hello/<name>')
def hello(name='None'):
    return render_template('hello.html', name=name)

https://pythonbasics.org/flask-tutorial-routes/

Blueprints

  • Another helpful concept with flask is the idea of 'blueprints'. Blueprints are essentially apps within the app. They allow the app to be easily extended and assist in the organization of the app. They also allow the re-use of code.
  • There are two ways to organize the app with blueprints: Divisional and Functional. If the individual parts are more unique it's probably better to use Divisional, and Functional if more files are shared between components.
  • https://exploreflask.com/en/latest/blueprints.html

Databases

⚠️ **GitHub.com Fallback** ⚠️