Answer the question
In order to leave comments, you need to log in
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 %}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question