简体   繁体   中英

how to check for condition on each page after a user has logged in in django

I have a condition, whether a user has setup some account information or not. If a user does not meet this condition, I want to throw a popup on the screen.

How can I accomplish this in the most resource efficient way, so as to not have to query the database for every view a user hits. Or is this not a problem because it is optimized through django?

Look into implementing a decorator for the view you are interested in restricting access to - Django provides some decorators that are useful. If you do not find one that fits your needs perfectly, consider writing a custom one.

Edit: To reduce the number of database hits, you should save the results in the cache/session.

我最终针对我的特定情况使用了上下文处理器,但是对于检查条件,我相信定制中间件是解决方案。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM