title: how to make messages showed up in the template
body: <p>i have a login django app where i am trying to inform user in if they have wrong credentials  or if they are successfully login.</p>
  
  <p>the problem is that i used the message framework in django but it did not showed up in the template.</p>
  
  <h1>views.py</h1>
  
  <pre><code>from django.contrib import messages
  
  
  def login_request(request):
      if request.method == "POST":
          username = request.POST['lognName']
          password = request.POST['lognCode']
          user = authenticate(username = username,password = password)
          if user is not None:
              login(request,user)
              messages.info(request,f"You are now logged in as {username}")
              return redirect("main")
          else:
              messages.error(request,"invalid username or password")
  
      return render(request,'login.html')
  </code></pre>
  
  <h1>login.html</h1>
  
  <pre><code>{% if messages %}
      {% for message in messages %}
          &lt;script&gt;M.toast({html:"{{message}}",classes:'blue rounded',displaylength:2000});&lt;/script&gt;
      {% endfor %}
  {% endif %}
  </code></pre>
  
  <p>even if i tried to used outside the if statement the toast doesn't work </p>