Мне нужно выделить текст проверки цветом
Когда я начинаю проверять слова, у меня то, что пришло, выделено зеленым, а ошибка - красным, и когда у меня ошибка, он не выделяет ее красным, а только показывает сообщение об ошибке. Как я могу сделать так, чтобы он выделял ошибку?
view.py
@login_required
@permission_required("service.add_post")
def create_post(req):
form = PostForm()
if req.method == "POST":
form = PostForm(req.POST)
if form.is_valid():
form.save()
title = form.cleaned_data.get("title")
if title != "POST":
messages.error(req, f"Something went wrong")
return redirect('index')
# id = form.cleaned_data.get("pk")
messages.success(req, f"Post {title} was created successfully")
return redirect('index')
return render(req, "create_post.html", {"form":form})
create_post.html
{% extends "index.html" %}
{% block content %}
<h1>Create Post</h1>
<form action="" method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<button class="btn btn-primary">Create New Post</button>
{% endblock %}
```
Already changed a lot of things but nothing helped.[](https://i.stack.imgur.com/dbS3i.png)
Попробуйте реализовать это в своем шаблоне:
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }} msg">
{{ message }}
</div>
{% endfor %}
{% endif %}