Моя ошибка django должна отображаться красным цветом, но это не так ( она показывает обычный текст), в то время как мое сообщение об успехе отображается зеленым цветом
so when i fill the login info correctly i get a message 'successfully added (username)' but when i fill in the wrong info i just shows plain black text but i want it to show error message in red color the tutorial .I followed a tutorial (by correy schafers) exactly the same but somehow i cant get the error message to show up in red color but my my success message shows up in green. register.html {% extends "blog/base.html" %} {% load crispy_forms_tags %} {% block content %} <div class="content-section"> {% csrf_token %} Join Today {{ form|crispy }} <div class="form-group"> Sign Up </div> <div class="border-top pt-3"> <small class="text-muted"> Already Have An Account? <a class="ml-2" href="#">Sign In</a> </small> </div> </div> {% endblock content %} base.html {% load static %} {% if title %} <title>Django Blog - {{ title }} {% else %} <title>Django Blog {% endif %} <div class="container"> <a class="navbar-brand mr-4" href="{% url 'blog-home' %}">Django Blog</a> <span class="navbar-toggler-icon"></span> <div class="collapse navbar-collapse" id="navbarToggle"> <div class="navbar-nav mr-auto"> <a class="nav-item nav-link" href="{% url 'blog-home' %}">Home</a> <a class="nav-item nav-link" href="{% url 'blog-about' %}">About</a> </div> <div class="navbar-nav"> <a class="nav-item nav-link" href="#">Login</a> <a class="nav-item nav-link" href="#">Register</a> </div> </div> </div> <div class="row"> <div class="col-md-8"> {% if messages %} {% for message in messages %} <div class="alert alert-{{ message.tags }}"> {{ message }} </div> {% endfor %} {% endif %} {% block content %}{% endblock %} </div> <div class="col-md-4"> <div class="content-section"> <h3>Our Sidebar</h3> <p class="text-muted">You can put any information here you'd like. </p><ul class="list-group"> <li class="list-group-item list-group-item-light">Latest Posts</li> <li class="list-group-item list-group-item-light">Announcements</li> <li class="list-group-item list-group-item-light">Calendars</li> <li class="list-group-item list-group-item-light">etc</li> </ul> <p></p> </div> </div> </div> views.py from django.shortcuts import render, redirect from django.contrib import messages from .forms import UserRegisterForm def register(request): if request.method == 'POST': form = UserRegisterForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') messages.success(request, f'Account created for {username}!') return redirect('blog-home') else: form = UserRegisterForm() return render(request, 'users/register.html', {'form': form}) forms.py from django import forms from django.contrib.auth.models import User from django.contrib.auth.forms import UserCreationForm class UserRegisterForm(UserCreationForm): email = forms.EmailField() class Meta: model = User fields = ['username', 'email', 'password1', 'password2'] What I have tried: i tried to copy the tutorial as best as i can
Richard MacCutchan
Спросите человека, который написал учебник.