GithubHelp home page GithubHelp logo

flask-in-docker's Introduction

Simple Python Flask Dockerized Application

This will walk through the steps to get a Flask App running locally, with autoreload

    1. Install Docker https://www.docker.com/docker-toolbox
    1. fork this repo to your own GH account
    1. clone it
    1. go to web dir of this repo
    1. run docker-compose up
    1. go to 127.0.0.1:5000 (if it doesn't work, you can run docker-machine ip, this might be the IP you have to use)

To install new libraries

  • Add them to requirements.txt
  • run docker-compose build

Style Guide

  • Never use tabs, instead use 4 spaces
  • Use single quotes for strings, e.g. foo = 'bar' instead of foo = "bar"
  • Use Doc strings for all your functions, explain what they do
  • Use descriptive file names, e.g. index instead of i
  • Try to keep it DRY
  • Use comments where needed
  • Don't commit to master, but make a new branch. This way your PR can be reviewed
  • use camel_case as variable names

Exercises

The goal of these exercises are to learn some python + flask. Make sure your code is clean as described in the style guide.

Ex. 1 Finish the people API

In the function descriptions (in api/people.py) is described what it should do. Your job to make sure it does!

Hints:

Ex. 2 Create a tasks API

Use the following fixtures

static_tasks = [{
    'id': 1,
    'name': 'Clean up',
    'status': 'done'
},
{
    'id': 2,
    'name': 'Fix your car',
    'status': 'todo',

},
{
    'id': 3,
    'name': 'programming some Flask',
    'status': 'work in progress',
}]

Requirements

  • Do it in a new file, on a logical place
  • create a get single API
  • create a get many API
    • filters:

      • name (like filter)
      • status (equals filter)
    • sort_by:

      • id
      • name
      • status
    • pagination

      • results_per_page (default=1)
      • page_number (default = 0)

Hints

  • reuse some functions of the people API, (maybe put those 'helper' functions in a new file??)

Ex. 3 People overview in HTML

With Jinja2 you can render html templates. Your goal is to get an overview of all people on this page.

Do this by performing following steps:

  • update the people_route function in app.py
  • call your own api get many people FUNCTION.
  • extract the json of this response object (hints: use response attr of this object)
  • transform this json into a dict with json.loads
  • extract people from this dict
  • pass this value to your template
  • in your template loop over this dict (hint: Try to find out how this works in jinja2 docs)
  • print the people dynamically

extra

  • Can you make filtering/pagination work for these routes? A route could be: /people/?name=Peter
    • hint: or can you explain why this already works?
  • Can you display the correct time (in ISO format) this page was rendered. (hint: try to find a library that does this & pass this variable to your template)
  • Can you put this time in the meta data of your api routes as well? Make sure it's DRY!

Ex. 4 Tasks overview in HTML

Can you do Ex. 3 but then for tasks?

Ex. 5 Can you add more functionality to this app?

For inspiration, check other flask tutorials. Feel fry to install other libraries etc.

flask-in-docker's People

Contributors

petervtzand avatar

Watchers

 avatar  avatar

Forkers

roel4811

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.