Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8298857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:56:13+00:00 2026-06-08T15:56:13+00:00

here’s a conundrum for you, Using Django 1.4, I cannot get messages set through

  • 0

here’s a conundrum for you,

Using Django 1.4, I cannot get messages set through the messages middleware to display in my templates. I have combed through the Django docs and ensured that my settings.py file referenced the relevant apps, context-processors and middleware. I have ensured that my view is rendering with the RequestContext instance. Yet, I still cannot get any of the messages to appear in the template.

settings.py:

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
...
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.messages.context_processors.messages',
'tekextensions.context_processors.admin_media_prefix',
)
...
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin', #Admin interface
'django.contrib.admindocs', #Admin docs
...

My messages error_level is set to 20 (i.e. ‘info’ and above). I am using the default mappings.

views.py:

from django.contrib import messages

def index(request, *args, **kwargs):
    #Do some funky jazz which works like build the timeline & page vars
    ...
    messages.error = (request,"Horsey Bollox!")
    messages.add_message = (request, messages.ERROR,"Why won't this f***ing thing work?") #Attempting alternate method
    return render_to_response('funkyjazzdirectory/index.html',
                        {
                            'page': page, 
                            'timeline': timeline,
                        },
                        context_instance=RequestContext(request))

template: (funkyjazzdirectory/index.html)

{% extends "base.html" %}
{% if messages.error %}
    <div class="messages-errors">
        Error:
        <ul>
            {% for msg in messages %}
                <li>{{msg}}</li>
            {% endfor %}
        </ul>
    </div>
{% endif %}
<p>
    Other stuff such as iterating through {{timeline}} which renders absolutely fine
</p>

I have also tried substituting {{msg}} with:

<li>{{msg.message}}</li>

with no success.

The rest of the page outputs fine, Django does not throw an error. The console does not contain anything abnormal. The HTML code produced does not contain the div, nor the list tags anywhere. The template which this one extends (base.html) does not use the {{messages}} variable nor call a template tag which uses it.

I have tried passing the {{messages}} into a custom template tag for testing in the top of the index.html template. Here I can do:

def __init__(self, messages):
    self.messages = messages
    def render(self, context):
    l = dir(context[self.messages])
        print(l)

…which produces a list of methods / properties presumably of the message object. Yet, I cannot iterate over this at all, as “for m in messages:” does not run even once. Attempting to discover the size of this entity by:

print(len(context[self.messages]))

gives me nothing in the console.

The only time I’ve got it to actually output anything was when I manually passed the messages object into the template within the render_to_response tag then iterated over messages.error ({% for msg in messages.error %}) which produced two bullet points in the correct div: the first being filled with what looks like a var dump: “, POST:, COOKIES:{‘csrftoken’:”… the second bullet point containing just the last error message: “Why won’t this f***ing thing work?”. (Obviously this was just a test and I have not kept messages in the dict passed via render_to_response as I know it should arrive in the template via the context)

So, where did I go wrong?

Why can I not see my error messages in my template? Why can I not even get the messages to appear in the console?

Any light someone smarter than me can shed would be extremely helpful!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:56:14+00:00Added an answer on June 8, 2026 at 3:56 pm

    You seem to use a very strange way to add a message:

    messages.error = (request,"Horsey Bollox!")
    messages.add_message = (request, messages.ERROR,"Why won't this f***ing thing work?") 
    

    The correct syntax is:

    messages.error(request,"Horsey Bollox!")
    messages.add_message(request, messages.ERROR,"Why won't this f***ing thing work?") 
    

    The settings and templates are however fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here's the basic setup: I have a thin bar at the top of a
Here is my problem : I have a post controller with the action create.
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the
Here is an example: I have the generic type called Account. I wish to
Here is the problem that I am trying to solve. I have two folders
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here is my program to find all the subsets of given set. To solve
Here is my code...I have two dimensional matrices A,B. I want to develop the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.