Why is flask rendering the wrong template

  flask, python

UI = Blueprint('UI', __name__, static_folder='static', static_url_path='/static/UI', template_folder='templates')

web = Blueprint('web', __name__, static_folder='static', static_url_path='/static/web', template_folder='templates')

My projects uses two different Blueprints which use different templates, the app folder has two subfolders for each blueprint (UI,web) and each one has two folders (static,templates),




@UI.route('/dashboard', methods=['GET', 'POST'])   
def login():
   
    usr = Admin.query.filter_by(username="admin").first()
    if not usr:
        if request.method == "POST":
            if 'passwrd' in request.form:
                # irrelevant code goes here

        return render_template('create_password.html')


    ## this will be triggered if admin is Found 
    if request.method == 'POST':
        if request.form['passwrd']:
            ### irrelevant code goes here


    return render_template('Alogin.html')

when I try to access 127.0.0.1:5000/dashboard the templates from the web blueprint are rendered

I tried changing the template_folder parameter but the wrong template is still being rendered

Source: Python Questions

One Reply to “Why is flask rendering the wrong template”

  • I got the same exact thing happening. I’m assuming you have an ‘ALogin.html’ in both templates folders? Did you find out something? I mean I just renamed my template, which fixed it, but still, it’s weird.
    In the docs I read that the main templates folder has higher precedence than the blueprint ones, but another blueprint templates folder over the current one?

LEAVE A COMMENT