Skip to content

v.2.9.0

Latest
Compare
Choose a tag to compare
@marcuxyz marcuxyz released this 29 Nov 01:30
567248c

What's Changed

  • Create support for calling callbacks on specific actions by @marcuxyz in #56

Previously you could only run callbacks for all routes. For example,

Before:

from flask import render_template

before_request = ["set_user"]

def index(self):
    return render_template('users/index.html', user=self.user)

def show(self):
    return render_template('users/show.html', user=self.user)

def set_user(self):
    self.user = 'Joe'

To both routes index and show you can call self.user.

Now, you can use dict structure to control the before_request callback.

before_request = dict(callback="set_user", actions="show")

See:

from flask import render_template

before_request = dict(callback="set_user", actions="show")

def index(self): 
    # self.user is not implemented here
    return render_template('users/index.html')

def show(self):
    return render_template('users/show.html', user=self.user)

def set_user(self):
    self.user = 'Joe'

Now you can invoke the callback only on the action of your choice

Full Changelog: v2.8.3...v2.9.0