Почему цвет метки кнопки отличается от того, что вы видите на изображении?

<!DOC TYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Home Page</title>
    </head>
    <body>
        {%for message in messages%}
        <div class="alert alert-{{message.tags}}alert-disimissible fade show"role="alert">
        <strong>Message:</strong>{{message}}
        <button type="button" class="close" data-dismiss="alert" aria-label="close">
        <span aria-hidden="true">&times;</span>
        </button>
        </div>
        {% endfor %}
    
    
        <h3>Welcome!</h3>
        {%if user.is_authenticated%}
        <h3>hello{{fname}}</h3}       
        <button type="submit"><a href="/signout">signout</a></button>
        {% else %}
        <button type="submit"><a href="/signup">SignUp</a></button>
        <button type="submit"><a href="/signin">SignIn</a></button>
        {% endif%}
    
        
    </body>
    </html>

я создаю форму входа в django, можете ли вы сказать, что не так с приведенным выше кодом, так как кнопка выхода не отображается, когда я запускаю ее

<!DOC TYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Home Page</title>
    </head>
    <body>
        {%for message in messages%}
        <div class="alert alert-{{message.tags}}alert-disimissible fade show"role="alert">
        <strong>Message:</strong>{{message}}
        <button type="button" class="close" data-dismiss="alert" aria-label="close">
        <span aria-hidden="true">&times;</span>
        </button>
        </div>
        {% endfor %}
    
    
        <h3>Welcome!</h3>
        {%if user.is_authenticated%}
        <h3>hello{{fname}}</h3>}       
        <button type="submit"><a href="/signout">signout</a></button>
        {% else %}
        <button type="submit"><a href="/signup">SignUp</a></button>
        <button type="submit"><a href="/signin">SignIn</a></button>
        {% endif%}
    
        
    </body>
    </html>

Вы допустили опечатку в <h3>{hello {{fname}}</h3. Вам не хватает > в конце тега h3.

  • Старайтесь называть свои урлы так
path('logout/', views.logout_view, name="logout"),
  • В шаблоне это может быть использовано как:
href="{% url 'logout' %}"
<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Home Page</title>
    </head>

    <body>
        
        {% for message in messages %}
            <div class="alert alert-{% if message.tags == 'error' %}danger{% else %}{{message.tags}}{% endif %} alert-disimissible fade show" role="alert">
                <strong>Message:</strong>{{message}}
                <button type="button" class="close" data-dismiss="alert" aria-label="close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
        {% endfor %}

        <h3>Welcome!</h3>
        {% if user.is_authenticated %}
            <h3>hello {{ fname }}</h3>
            <!-- Try to not use hard urls like /signout -->
            <!-- Instead use {% url 'urlname' %} -->
            <button type="submit"><a href="/signout">signout</a></button>
        {% else %}
            <button type="submit"><a href="/signup">SignUp</a></button>
            <button type="submit"><a href="/signin">SignIn</a></button>
        {% endif%}
    </body>

</html>
Вернуться на верх