弹出窗口不显示Django消息

时间:2015-06-18 18:54:25

标签: python django django-messages

我有一个Django网站,根据用户选择显示不同的甘特图。我的代码中有一堆Django的日志消息,并希望能够在用户点击提交按钮后设置然后在弹出窗口中显示,但我似乎无法将消息发送到在弹出窗口中显示。

我的views.py看起来像这样:

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})

结果模板包含我必须显示弹出链接的代码,如下所示:

<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>

messages.html模板如下所示:

<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>

弹出窗口可以正常工作,但是当它打开时,我会看到<django.contrib.messages.storage.fallback.FallbackStorage object at 0x10965bdd0>而不是消息列表。这些消息在我的结果页面顶部显示时会正确显示,但我不希望它们出现在那里。

有谁能告诉我如何解决这个问题?

谢谢!

0 个答案:

没有答案