Giter Club home page Giter Club logo

minimal-flask-example-1's Introduction

minimal-flask-example

The simplest complex example that I can think of to show main Flask app concepts.

All examples are in app.py. There are 3 view functions embedded, each showing a different example of how to build Flask apps.

Key concepts applicable throughout:

  • View functions
  • Routes
  • Returning a template.

example 1

The first example is under /df. In this example, I show you how to embed a pandas.DataFrame() table inside an HTML page served up using Flask, essentially as a dump of the table.

Key concepts here:

  • Jinja2 templating: ({{ variable_name }} syntax)
  • Template inheritance: ({% extends "parent.html" %})
  • Styling with Bootstrap CSS
  • Marking strings as safe to render: ({{ string|safe }})

example 2

The second example is under /dfcustom. In this example, I show you how to apply custom formatting to a DataFrame rendered as an HTML table.

Key concepts here, building on top of example 1:

  • Jinja2 syntax is very Python-like.
  • Macros behave like Python functions.
  • Looping is very Pythonic.

example 3

The second example is /bokehplot. In this example, I show you how to embed a Bokeh plot on an HTML page served up using Flask.

Key concepts here:

  • Marking strings as safe to render (see above)
  • Refactoring granular logic into a utility function, so that only application "business logic" remains.
  • It is possible to cleverly pass strings around so that you can keep things like versioning automatically correct.

minimal-flask-example-1's People

Contributors

ericmjl avatar pyup-bot avatar antoinearnoud avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.