Flask web development, one drop at a time

Flask web development, one drop at a time

A really quick intro to Flask.

Presented during the Python Web Framework Royal Rumble @ PyCon Sette, 2016. Competitors where Django, Pyramid and TurboGears.

Alex Martelli being in the room and validating his own quote did help to win the cause /me smirks

E3550767c858c787c35c280047ff789c?s=128

Nicola Iarocci

April 16, 2016
Tweet

Transcript

  1. 1.
  2. 2.

    HELLO.PY from flask import Flask app = Flask(__name__) @app.route("/") def

    hello(): return "hello world" if __name__ == "__main__": app.run()
  3. 3.
  4. 13.
  5. 14.
  6. 20.

    SIGNED SESSION COOKIES session allows you to securely store information

    specific to a user from one request to the next
  7. 25.

    HELLO.PY from flask import Flask app = Flask(__name__) @app.route("/") def

    hello(): return render_template('hello.html') if __name__ == "__main__": app.run()
  8. 26.

    HELLO.HTML {% extends 'layout.html' %} {% block title %}Greetings{% endblock

    %} {% block body %} <h1>Hello {{ name }}!</h1> {% endblock
  9. 27.

    LAYOUT.HTML <!doctype html> <head> <title>{% block title %}{% endblock %}</title>

    </head> <body> {% block body %}{% endblock %} </body>
  10. 28.

    INSTALL AND RUN $ pip install Flask $ python hello.py

    * Running on http://localhost:5000/
  11. 29.

    EXTENSIONS RUNDOWN: FLASK-SQLALCHEMY from flask import Flask from flaskext.sqlalchemy import

    SQLAlchemy app = Flask(__name__) db = SQLAlchemy(app) class User(db.Model): name = db.Column(db.String(40), primary_key=True) email = db.Column(db.String(100)) @app.route('/user/<name>') def show_user(name): user = User.query.filter_by(name=name).first_or_404() return render_template('user.html', user=user)