Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django messages not showing

I'm trying to use django messages framework to display a message when a user signs out of my application. I'm new to django and the documentation isn't very clear to me. Why is my message not showing up?

https://docs.djangoproject.com/en/dev/ref/contrib/messages/#adding-a-message

VIEW.PY

from django.contrib import messages

def signout(request):
    logout(request)
    messages.add_message(request, messages.INFO, 'Signout Successful.')
    return HttpResponseRedirect(reverse(index))

def index(request):
    lf = LoginForm()
    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                auth_login(request, user)
    return render_to_response('test/home.html', {'login_form': lf,}, context_instance=RequestContext(request))

TEMPLATE - index

{% if messages %}
<ul class="messages">
    {% for message in messages %}
    <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
    {% endfor %}
</ul>
{% endif %}

I'm using django1.3. And the following is required (note that .tz is commented out)

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    #"django.core.context_processors.tz",
    "django.contrib.messages.context_processors.messages")

From documentation on TEMPLATE_CONTEXT_PROCESSORS:

New in Django 1.3: The django.core.context_processors.static context processor was added in this release.

New in Django 1.4: The django.core.context_processors.tz context processor was added in this release.

like image 512
thedeepfield Avatar asked Aug 06 '12 18:08

thedeepfield


1 Answers

Did you add the context processor and the middleware?

like image 148
Skylar Saveland Avatar answered Oct 08 '22 21:10

Skylar Saveland