Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weaving flask's render_template function #26

Open
N00bAdrian opened this issue Apr 4, 2023 · 0 comments
Open

Weaving flask's render_template function #26

N00bAdrian opened this issue Apr 4, 2023 · 0 comments

Comments

@N00bAdrian
Copy link

I am working on building software product lines for Flask applications and I am trying to use an aspect to make Flask's render_template function render from another HTML file:

from flask import render_template, Blueprint, url_for, redirect, request
from flask.views import MethodView
...

from aspectlib import Aspect, Proceed, weave

...

bp = Blueprint('home', __name__, template_folder='../templates')

class MessageForm(Form):
    ...

@Aspect
def render_author(*args, **kwargs):
	print("Rendering page with author information...")
	yield Proceed('homeWithAuthor.html', **kwargs)

class HomeView(MethodView):

    def get(self):
        with weave(render_template, render_author):
            form = MessageForm(request.form)
            messages = db.session.execute(db.select(Message)).scalars()
            return render_template(
                "home.html", 
                form=form,
                messages=messages
            )

    def post(self):
        ...
    
bp.add_url_rule("/", view_func=HomeView.as_view("home"))

The app would render from the original file instead of the stated file in the aspect though. There were no errors in weaving and running the app. Upon inspection with a debugger, the aspect has not been called at all. I have tried other arguments in the weaver including

weave('render_template', render_author)
weave('flask.render_template', render_author)
weave(flask.render_template, render_author)
weave('flask', render_author, methods='render_template')

and they all have the same result. The weaver works with builtin functions and class methods so I think it is an issue of me not weaving the aspect correctly.

Any help is appreciated, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant