Search code examples
flaskjinja2flask-security

Trouble extending Flask-Security login template


I'm using Flask-Security in my project and I would like to extend templates (namely login) it offers, in order to style them with custom CSS. Following the documentation, I've changed the SECURITY_LOGIN_USER_TEMPLATE config value to point to my template. In this template I'm extending the template provided by Flask-Security ("security/login_user.html") and changing the content of some of the blocks it defines (or its base).

My template renders as expected (looks like the standard "security/login_user.html"), the only problem being is that the blocks I'm trying to overwrite are not overwritten.

My template looks like this: login.html:

{% extends "security/login_user.html" %}

{% block content %}
<p>There should be no form.</p>
{% endblock content %}

To confirm that I'm not not rendering the original template I've tried changing contents of the template file to empty and it works as expected - nothing is rendered.

What am I missing?


Solution

  • After some time with debugger, I realized that something is wrong with the package Flask-Security that is available on PyPi. When developing my project I relied on source code that is present on their official github page. If you take a look at the login template, you notice that it indeed extends base template which provides definition of the blocks you can later overwrite.

    However when you download the package from PyPi and then check the template you notice that it differs - it does not use Jinja2 inheritance, nor does it use any blocks, therefore the problem described in the question.

    In other words, PyPi package is reflecting latest stable release (as noted by nick-k9), which differs significantly from develop branch.