Popup not showing Django messages
I have a Django site that displays various gantt charts based on user preferences. I have a bunch of Django registration messages in my code and you want to install and then display in the popup as soon as the user clicks the submit button, but I can't get the messages to show in the popup.
My views.py looks like this:
from django.contrib import messages
def gantt_search(request):
if request.method == 'POST':
messages.info(request,"Query submitted, beginning query results render for:")
form_start = WINDOW_START_Form(request.POST,section_label="WINDOW_START")
if form_start.is_valid():
WS_raw = form_start.cleaned_data['WINDOW_START']
messages.info(request,"Window Start time: {WS}".format(WS=WS_raw))
else:
messages.error(request,"The start date you entered is incorrectly formatted.")
else:
messages.info(request,"Rendering query page")
form_start = WINDOW_START_Form(section_label="WINDOW_START")
return render(request, 'InterfaceApp/table_search.html', {'window_start': form_start})
def msgs(request):
m = messages.get_messages(request)
return render_to_response('InterfaceApp/messages.html',{'message':m})
The result template contains the code that should display the popup message and looks like this:
<html>
<head>
<title>Search Results</title>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
function popitup(url) {
newwindow=window.open(url,'{{title}}','height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
}
</script>
</head>
<body>
<div class="container">
<a href="messages.html" onclick="return popitup('/InterfaceApp/msgs')" > {% trans 'View Log Messages' %}
</a>
</div>
</body>
</html>
The messages.html template looks like this:
<body>
<div class="container">
<h2>Messages</h2>
{{ message }}
</div>
<div class="containter">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>
{% if message.level == DEFAULT_MESSAGE_LEVELS.DEBUG %}Important: {% endif %}
{{ message }}
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</body>
The popup works fine, but when it opens, I see <django.contrib.messages.storage.fallback.FallbackStorage object at 0x10965bdd0>
a message list instead. The messages are displayed correctly at the top of the results page when they are displayed, but I don't want them there.
Can anyone tell me how to fix this?
Thank!
source to share
No one has answered this question yet
Check out similar questions: