pythontemplatesjinja2template-inheritance

Why isn't the head section of jinja inheritance loading for me?


I'm trying to do template inheritance to the following two pages and everything is being inherited but the title of my page. I've tried several variations on placing the title in different locations but still nothing. By the way I'm working this on my localhost.

Here is my code:

base.html

<!DOCTYPE html>
<html lang="en">
<head>
    {% block head %}
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>{% block title %}{% endblock %} - My Webpage</title>
        <link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cerulean/bootstrap.min.css" rel="stylesheet" integrity="sha384-zF4BRsG/fLiTGfR9QL82DrilZxrwgY/+du4p/c7J72zZj+FLYq4zY00RylP9ZjiT" crossorigin="anonymous">
    {% endblock %}
</head>
<body>
    <div class="container">
        {% block content %} {% endblock %}
    </div>
</body>
</html>

login.html

{% extends "base.html" %}
{% block head %}{% endblock %}
{% block title %} Log In {% endblock %}
{% block content %}
    <h2>Log In</h2>
    <a href="/signup">Sign Up</a>
    <form method="post">
        <label for="username">Username:</label>
        <input id="username" type="text" name="username" value="{{username}}">
        {{username_error}}
        {{user_not_found}}
        <br>
        <label for="pass">Password:</label>
        <input id="pass" type="password" name="password" value="">
        {{incorrect_password}}
        {{password_error}}
        <br>
        <button>Submit</button>
    </form>
{% endblock %}

Solution

  • Turns out I just had to take out the head block for the head and title section to load. Reason why I didn't do it earlier is because I had another template that had to use some specific css that was in the header.

    {% extends "base.html" %}
    {% block title %} Log In {% endblock %}
    {% block content %}
        <h2>Log In</h2>
        <a href="/signup">Sign Up</a>
        <form method="post">
            <label for="username">Username:</label>
            <input id="username" type="text" name="username" value="{{username}}">
            {{username_error}}
            {{user_not_found}}
            <br>
            <label for="pass">Password:</label>
            <input id="pass" type="password" name="password" value="">
            {{incorrect_password}}
            {{password_error}}
            <br>
            <button>Submit</button>
        </form>
    {% endblock %}