Quick GitHub and Flask Introduction

Getting Started

  1. Signup (or login) for a GitHub account at https://github.com/.
  2. Make your way over to https://github.com/malvern-code-club/plant-system/.
  3. Fork the repository to make a copy of it in your account.

Making a new Simple Route

Making a Pull Request

Serving a HTML File in a route

# ...

@app.route("/htmlserve")
def htmltest():
    return app.send_static_file("mypage.html")
<html>
    <head>
        <title>My Page</title>
    </head>
    <body>
        <h1>Hello!</h1>
    </body>
</html>

/app.py

/mypage.html

Serving a File with a Template Engine and Parameter

from flask import render_template

#####################################
# /!\ REMEMBER TO IMPORT THE MODULE #
#     ABOVE OR IT WON'T WORK!       #
#####################################

# ...

@app.route("/hello/<name>")
def say_hi(name):
    # You could just return the name in a simple
    # route like before like this:
    #  return "Hello " + name
    return render_template("hello.html", name=name)
<html>
    <head>
        <title>My Page</title>
    </head>
    <body>
        <h1>Hello {{name}}!</h1>
    </body>
</html>

/app.py

/mypage.html

Made with Slides.com