Django - Check users messages every request
Posted
by
Hanpan
on Stack Overflow
See other posts from Stack Overflow
or by Hanpan
Published on 2010-12-23T11:35:26Z
Indexed on
2010/12/23
11:54 UTC
Read the original article
Hit count: 205
django
Hi,
I want to check if a user has any new messages each time they load the page. Up until now, I have been doing this inside of my views but it's getting fairly hard to maintain since I have a fair number of views now.
I assume this is the kind of thing middleware is good for, a check that will happen every single page load. What I need it to do is so:
- Check if the user is logged in
- If they are, check if they have any messages
- Store the result so I can reference the information in my templates
Has anyone ever had to write any middleware like this? I've never used middleware before so any help would be greatly appreciated.
© Stack Overflow or respective owner