I
I
Insssane2021-06-08 20:40:12
HTML
Insssane, 2021-06-08 20:40:12

Flask html template inheritance not working, how to fix it?

When inheriting, the parent template "base.html" does not see the child "navbar.html", "cardslider.html".

base.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">

  <link rel="stylesheet" href="{{ url_for('static', filename='css/index.css') }}">
  <link rel="stylesheet" href="{{ url_for('static', filename='css/cardslider.css') }}">

  <title>Title</title>
</head>
<body>

{% block navbar %}{% endblock %}

{% block cardslider %}{% endblock %}


<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>


</body>
</html>


"navbar.html"
{% extends "base.html" %}
{% block navbar %}
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">Navbar</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNavDropdown">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link active" aria-current="page" href="#">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Features</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Pricing</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        Dropdown link
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                        <li><a class="dropdown-item" href="#">Action</a></li>
                        <li><a class="dropdown-item" href="#">Another action</a></li>
                        <li><a class="dropdown-item" href="#">Something else here</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <ul class="navbar-nav justify-content-end">
        <li class="nav-item">
            <a class="nav-link" href="#">Зарегистрироваться</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#">Войти</a>
        </li>
    </ul>
</nav>
{% endblock %}


"cardslider"
{% extends "base.html" %}

{% block cardslider %}
<div class="slider middle">
    <div class="slides">
        <input type="radio" name="r" id="r1" checked>
        <input type="radio" name="r" id="r2">
        <input type="radio" name="r" id="r3">
        <input type="radio" name="r" id="r4">
        <input type="radio" name="r" id="r5">

        <div class="slide s1"><img src="" alt=""></div>
        <div class="slide"><img src="" alt=""></div>
        <div class="slide"><img src="" alt=""></div>
        <div class="slide"><img src="" alt=""></div>
        <div class="slide"><img src="" alt=""></div>
    </div>

    <div class="navigation">
        <label for="r1" class="bar"></label>
        <label for="r2" class="bar"></label>
        <label for="r3" class="bar"></label>
        <label for="r4" class="bar"></label>
        <label for="r5" class="bar"></label>
    </div>

</div>
{% endblock %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yupiter7575, 2021-06-08
@Insssane

If you want to place different blocks in different files, then you do not need inheritance.
Use the include function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question