0

I'm wanting to display a message to the user after they are logout and are redirected to the homepage. I know this likely doesn't work because I am trying to display the message before returning a redirect to the homepage.

views.py

def logout_request(request):
    logout(request)
    messages.info(request, "Logged out successfully!")
    return redirect("main:homepage_view")
GTA.sprx
  • 817
  • 1
  • 8
  • 24
  • That should work. Are you displaying messages on the home page? They don't magically appear, you have to [display them](https://docs.djangoproject.com/en/3.0/ref/contrib/messages/#displaying-messages). – Selcuk Feb 20 '20 at 23:18

1 Answers1

0

vieviews.py

        messages.success(request, 'You are now logged out')

settings.py

        from django.contrib.messages import constants as  messages
        MESSAGE_TAGS = {
            messages.ERROR: 'error'
            }

alert.html -- uses bootstrap

    {% if messages %}
        {% for message in messages %}
             < div id="message" class="container-fluid animated fadeInUp" style="position:absolute; z-index:1000; top:32%;">
                  < div class="row text-center">
                       < div class="ml-auto mr-2 col-4 alert alert-{{ message.tags }} alert-dismissible text-center" role="alert">
                           < button type="button" class="close" data-dismiss="alert">< span aria-hidden="true">&times;</span>. 
                           </button>
                           < strong>
                               {% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}
                                   Error: 
                               {% else %}
                                    {{ message.tags|title }}
                               {% endif %}
                            </strong>
                           {{ message }}
                       </div>
                 </div>
               </div>
            {% endfor %}
      {% endif %}

base.html

    {% include 'alert.html' %}
mh-firouzjah
  • 834
  • 1
  • 6
  • 15