zorro76
@zorro76

Как объединить вывод django messages и плагин toastr?

Есть проект на django там выводятся ошибки, использую для этого такую не хитрую комбинацию:
{% for message in messages %}
    
    <div class="alert alert-{% if message.tags %}{{ message.tags }}{% endif %} alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button>
        <strong>{{ message }}</strong>
    </div>
    
    {% endfor %}

ошибки выводятся, каждому классу задан цвет
Теперь же задача сделать вывод с помощью плагина toastr
demo
я задал в ручную ошибки:
<script>
    toastr["success"]("Cush Cushion has been successfully launched on German marketplace.", "SUCCESSFUL LAUNCH");
    toastr["error"]("Your launch 0049378 has been declined.<br/><br/><button type='button' class='btn clear'>Learn more</button>", "launch declined");
    toastr["warning"]("Your launch has been saved as draft. To effectively launch it upload product promotional codes.<br /><br /><button type='button' class='btn clear'>Add Codes</button>", "saved as draft");
    toastr["info"]("Knee Pillow launch on United Kindom has been approved.", "lAUNCH APPROVED");
</script>

но понятное дело что ни будут формироваться и выводиться джангой.
гуглил этот вопрос и наткнулся только на такой вот вывод:

{% for message in messages %}

    toastr[{{ message.tags }}]({{ message }});

    {% endfor %}

но получается ерунда. Кто встречал подобное решение или знает как это объединить буду очень признателен за помощь.
  • Вопрос задан
  • 227 просмотров
Решения вопроса 1
zorro76
@zorro76 Автор вопроса
Решилось само собой:
<script>
    {% for message in messages %}
        toastr['{{ message.tags }}']('{{ message }}');
    {% endfor %}
    
</script>
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы