[Python] How can I use base.html like a regular template, and render to it

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have my navbar css in my base.html, and then use {% extend base.html %} to add it into my regular template. However, I want to have a login/register option in my navbar (which is in my base.html), and I want to use cookies to decide whether to put login or register in the navbar. How can I have base.html be able to request cookies, when it doesn't have a view? Also, not every webpage on my site has a view, some are a plain html with {% extend base.html %}.

    my base.html:

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-175481126-1"></script>
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'UA-175481126-1');
    </script>

    <style>
    ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: Tahoma, Geneva, sans-serif;
    background-color: #333;
    }
    li {
    float: left;
    border-right: 1px solid #bbb;
    }
    li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    }
    /* Change the link color to #111 (black) on hover */
    li a:hover {
    background-color: #111;
    color: white;
    text-decoration:none;
    }

    /* for buttons*/
    .paging {
    background-color: #333;
    border: none;
    color: white;
    padding: 8px 14px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    font-family: Tahoma, Geneva, sans-serif;
    }
    button:hover {
    background-color: #111;
    }

    .register {
    float: right;
    }

    .paging {
    background-color: #333;
    border: none;
    color: white;
    padding: 8px 14px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    font-family: Tahoma, Geneva, sans-serif;
    }
    button:hover {
    background-color: #111;
    }

    /* title */

    .title {
    color: black;
    padding: 10px;
    text-align: center;
    font-size: 40px;
    font-family: Tahoma, Geneva, sans-serif;
    Color: black;
    text-decoration: none;
    }

    /* descriptions */

    .description {
    color: black;
    padding: 15px;
    font-family: Tahoma, Geneva, sans-serif;
    text-align: left;
    font-size: 13px;
    }

    /* embedd url */
    .iframe-container{
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    height: 0;
    margin-left: auto; /* Automatic margin from left */
    margin-right: auto; /* Automatic margin from right */
    }
    .iframe-container iframe{
    position: absolute;
    top:0;
    left: 0;
    width: 100%;
    height: 100%;
    }

    /* make columns */

    * {
    box-sizing: border-box;
    }

    .row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    flex: 0 0 100%;
    max-width: 100%;
    /* you can just remove these margins all together. Just wanted to emphasize that there should be no margin left or right, to avoid overflow */
    margin-left: 0px;
    margin-right: 0px;
    }

    .videos, .ads {
    flex-grow: 0; flex-shrink: 0;
    }

    .ads {
    display: block;
    float: right;
    background-color: #c1c4c9;
    width: 25%;
    }

    .videos {
    display: block;
    float: left;
    width: 75%;
    padding-right: 10%;
    padding-left: 10%;
    }

    .image {
    padding-right: 5%;
    padding-left: 5%;
    padding-top: 5%;
    padding-bottom: 5%;
    }

    .logo {
    flex-direction:; row;
    flex:; 0 0 100%;
    max-width 100%;
    justify-content:; center;
    }

    .banner {
    /* float: left;*/
    width: 100%;
    height: 5%;
    background-color: red;
    color: white;
    text-align: center;
    }

    img {
    max-width: 100%;
    max-height: 100%;
    }

    /* header */
    .header {
    background-color: #F1F1F1;
    text-align: center;
    padding: 20px;
    font-family: Tahoma, Geneva, sans-serif;
    }
    </style>

    <html>

    {% load static %}

    <link rel="shortcut icon" type="image/png" href="{% static 'images/favicon.ico' %}"/>

    <div class="logo">
    <div class="header">
    <a href="/">
    <img src="https://i.ibb.co/5Rqps7F/logo-black.png" alt="Computer Man">
    </a>
    </div>

    <ul>
    <li class="all"><a href="/">All videos</a></li>
    <li class="stam"><a href="/stam">Stam videos</a></li>
    <li class="music"><a href="/music">Music videos</a></li>
    <li class="news"><a href="/news">News videos</a></li>
    <li class="contact"><a href="/contact">Contact</a></li>
    <li class="register"><a href="/register">Login/Register</a></li>
    </ul>

    <div class="banner">
    <text align="center">We are still developing our site, so we may not be able to update videos as often as we want</text>
    </div>
    </div>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

    Continue reading...

Compartilhe esta Página