Forums

Issues with template inheritance in Flask

Hi - I'm having some issues getting template inheritance to work correctly in my Flask app. My template (base.html) is appearing as intended but none of the body of the page is appearing.

Code below is a sample of what I'm using, with base.html in the /templates folder.

<html>
{% extends "base.html" %}
{% block body %}
<body>
    <b>This is a test index page</b><br>
    <i>This is testing if the italic tag works</i>
</body>
{% endblock %}
</html>

I'm a rookie with Flask, but my basic Googling around hasn't been able to find any issues with what I'm doing. Does anyone have any suggestions?

Thanks in advance!

I’m a rookie too but try changing {% block body %} to {% block content %}, that’s what I have and it works ok.

See https://flask.palletsprojects.com/en/1.1.x/patterns/templateinheritance/

Thanks @dreid - a rookie mistake on my behalf and embarrassing not to have picked that up!

Unfortunately the issue still exists, even with the above issue resolved.

what does your base.html look like?

@conrad ugh. Went back and had a look at it, hadn't declared {% block content %} correctly. Now resolved and working. Thanks for prompting me to check.

great, thanks for letting us know!