Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Nicola Iarocci

April 16, 2016
Tweet

More Decks by Nicola Iarocci

Other Decks in Programming

Transcript

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

    hello(): return "hello world" if __name__ == "__main__": app.run()
  2. SIGNED SESSION COOKIES session allows you to securely store information

    specific to a user from one request to the next
  3. HELLO.PY from flask import Flask app = Flask(__name__) @app.route("/") def

    hello(): return render_template('hello.html') if __name__ == "__main__": app.run()
  4. HELLO.HTML {% extends 'layout.html' %} {% block title %}Greetings{% endblock

    %} {% block body %} <h1>Hello {{ name }}!</h1> {% endblock
  5. LAYOUT.HTML <!doctype html> <head> <title>{% block title %}{% endblock %}</title>

    </head> <body> {% block body %}{% endblock %} </body>
  6. INSTALL AND RUN $ pip install Flask $ python hello.py

    * Running on http://localhost:5000/
  7. 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)