【问题标题】:I need to highlight the check text in color我需要用颜色突出显示检查文本
【发布时间】:2022-12-18 03:20:28
【问题描述】:

当我开始检查单词时,我有什么是绿色的,错误是红色的,当我有错误时,它不会用红色突出显示它,而只会显示我的错误信息。我怎样才能让它突出显示错误?

    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>
{% 端块 %} ```


Already changed a lot of things but nothing helped.[![enter image description here](https://i.stack.imgur.com/dbS3i.png)](https://i.stack.imgur.com/dbS3i.png)

【问题讨论】:

    标签: django


    【解决方案1】:

    尝试在您的模板中实现它:

    {% if messages %}
        {% for message in messages %}
                 <div class="alert alert-{{ message.tags }} msg">
                {{ message }}
           </div>
        {% endfor %}
    {% endif %}
    

    【讨论】:

      猜你喜欢
      • 2016-03-29
      • 2010-10-18
      • 1970-01-01
      • 1970-01-01
      • 2019-03-08
      • 2020-11-06
      • 2011-02-13
      • 2019-04-19
      • 2021-12-04
      相关资源
      最近更新 更多