Skip to content

Instantly share code, notes, and snippets.

@yi-mei-wang
Last active November 5, 2019 05:57
Show Gist options
  • Save yi-mei-wang/81e1845e78eedd7c97a4d59f916b09ae to your computer and use it in GitHub Desktop.
Save yi-mei-wang/81e1845e78eedd7c97a4d59f916b09ae to your computer and use it in GitHub Desktop.
Learning points for Intro to Flask lecture

What we will do in this lecture

  1. Set up Conda env

  2. Install the necessary packages

    1. pip install flask
    2. pip freeze > requirements.txt
  3. Set up Git repo

    1. git init + git remote add <url> OR
      1. This creates a LOCAL git repo, which you will LINK to a remote one (typically on GitHub)
    2. Create a repo on GitHub, git clone <remote url>
      1. This copies the folder onto your machine
  4. Set up Flask app

    1. Create a new Flask instance

    2. Run app (with debugging)

      1. flask run vs python app.py
    3. Create route(s)

      1. @app.route('/route')
    4. Create HTML templates

      1. MUST be inside templates folder
    5. Use Jinja to write Python-like code in HTML

      1. {% extends "_layout.html" %}
      2. if-else, for, etc inside HTML
        1. {% if username == 'kevin' %} {% end if%}
    6. Dynamic routing (e.g., users/<username>)

      1. We did not predefine routes called users/kevin or users/blake
    7. Pass variables to HTML

    8. Static files

      1. For images and CSS as they do not interact with the server, unlike HTML
      2. MUST be inside a static folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment