A
A
Artur Zenkov2016-03-26 14:04:40
Django
Artur Zenkov, 2016-03-26 14:04:40

How to pass dictionary to message?

Using SuccessMessageMixin for CBV, I'm trying to send a message so that the template can be accessed by keys.
But in the template, the message is turned into a string.
Are there ways to work with the dictionary in messages?
The only solution I found doesn't work.

views.py
...
def get_success_message(self, cleaned_data):
    return cleaned_data

succes.html

{% if messages %}
    {% for message in messages %}
    <p>{{ message.message.last_name }} {{ message.message.first_name }} </p>
    {% endfor %}
{% endif %}

Used Python 3.4.3 and Django 1.9.4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2016-03-27
@Hrom

Messages framework is not designed for this. If you really want to, you can make a crutch in the form of a filter that will convert the string into a dictionary and then use it in the template in the with construct.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question