Добавить новую строку в сообщение действий администратора - PullRequest
0 голосов
/ 05 ноября 2018

Как добавить новую строку, например, после запуска действия администратора.

from django.contrib import messages

messages.error(request, 'This is a line \n and this is another line')

Я также пытался с тегом html, но не работал.

1 Ответ

0 голосов
/ 05 ноября 2018

Я думаю, вам нужно переопределить часть admin.base template

Для соблюдения разрывов строк. Есть встроенный шаблон тега linebreaksbr

Блок переопределения в base_site.html будет:

<!-- The path and name for this file should be "templates/admin/base_site.html". -->
<!-- It overrides the original admin template and will be picked up by all of its children. -->
<!-- This template override has been verified for Django 1.11 and 2.0. -->

{% extends "admin/base_site.html" %}

{% block messages %}
    {% if messages %}
    <ul class="messagelist">{% for message in messages %}
      {# added linebreaksbr here #}
      <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message|capfirst|linebreaksbr }}</li>
    {% endfor %}</ul>
    {% endif %}
{% endblock messages %}

Пример взят из здесь

...