On Sep 30, 5:43 pm, Karen Tracey <kmtra...@gmail.com> wrote: > On Wed, Sep 30, 2009 at 4:14 PM, willfe <wil...@gmail.com> wrote: > > The infuriating part is the debug toolbar actually *shows the message* > > in the template context, in an attribute called 'messages'. > > If this template snippet is contained in a child template, is it somewhere > within a {% block %} tag?
Yes, it's within a block tag called "content". It's a stupidly simple base template right now (I haven't turned any of this loose on the designers yet): <html> <title>{% block title %}{% endblock %}</title> <body> <div class="header">Header</div> <div class="sidebar">Sidebar</div> <div class="content">{% block content %}{% endblock %}</div> <div class="footer">Footer</div> </body> </html> The template that's trying to display the messages attribute is similarly simple: {% extends "base.html" %} {% load i18n %} {% load account_extras %} {% block title %} {% trans 'Account Preferences' %} ({{ profile.username }}{% endblock %} {% block content %} {% if messages %} <ul> {{ messages }} {% for message in messages %} <li>{{ message }}</li> {% endfor %} </ul> {% endif %} ... other content follows, but it's just the form stuff (the form I'm passing from the view *does* appear/work as expected). In fact the entire template behaves properly except for showing "messages". I can edit values and save changes just fine. > > django.core.context_processors.auth shows an empty 'messages' list, > > though. > > I'm not sure what you are saying here. What are you looking at (and when), > exactly, that leads you to say 'auth' shows an empty messages list? Sorry I wasn't more clear on this :) I'm referring to the output provided by django-debug-toolbar. When I view its "Templates" tab (after saving the form, the same form is displayed again (for more editing), so there's no redirection here that could be munching the message), it displays four Context Processors: * django.core.context_processors.debug * django.core.context_processors.media * django.core.context_processors.auth * django.core.context_processors.i18n For each one, it can display what's assigned to each one, and within the auth context, it's showing: {'messages': [u'Preferences saved.'], 'perms': <django.core.context_processors.PermWrapper object at 0x01819350>, 'user': <User: wferrell>} Now that's a little different from before (previously, messages was just [] (empty)), but unfortunately the {% if messages %} bit in the template still acts as if messages is empty. Note I'm not actually setting messages anywhere; the documentation suggests (at least to me) that it's supposed to be set automatically by the auth middleware. Should I be explicitly calling get_and_delete_messages() and sending that to the template myself? [Update: the answer to this is "no, let the middleware do it". See below.] > I've usually found that data mysteriously not appearing in templates despite > the context containing the proper values is caused by mistakenly putting > things outside of block tags in child templates. I didn't realize that could happen ... funky. Though this hasn't solved the problem I'm describing, I'll make sure to keep this in mind as I roll out more templates. Thanks for the pointer. *sigh* I was just about to post this as-is, and tried one more thing, which fixed it. I hadn't added context_instance=RequestContext (request) to the end of the render_to_response() return in the specific method I was working with. I'd added it to a different one instead. It's fixed and working -- I'll put on a dunce cap and sit in the corner until I've learned my lesson :) Thanks again for your help. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---