If you want to completely redefine the behavior of the route, the best way is to override the MWOAuth class. Here is an example that works:
import os from flask import Flask, Blueprint from flask_mwoauth import MWOAuth app = Flask(__name__) app.secret_key = os.urandom(24) class MyMWOAuth(MWOAuth): def __init__(self, base_url='https://www.mediawiki.org/w', clean_url="Deprecated", default_return_to='index', consumer_key=None, consumer_secret=None, name="Deprecated"):
Let open /logout . You will see My custom logout . As you can see, BluePrint route registration takes place in the MWOAuth init method.
The second way is to use request callbacks . Here is an example that demonstrates a change in the response text after logging out.
from flask import g, request def after_this_request(f): if not hasattr(g, 'after_request_callbacks'): g.after_request_callbacks = [] g.after_request_callbacks.append(f) return f @app.after_request def call_after_request_callbacks(r): for callback in getattr(g, 'after_request_callbacks', ()): callback(r) return r @app.before_request def before_logout(): @after_this_request def after_logout(response):
Let open /logout . You will see Data from after_logout .
Hope this helps.
source share