开发者

Use Django context processor or middleware to check for cookies on templates?

开发者 https://www.devze.com 2023-03-03 15:08 出处:网络
My Django app has Post ob开发者_高级运维jects. Each Post has an IntegerField that gets incremented whenever a certain link is clicked. When that link is clicked, I set a cookie to indicate that it has

My Django app has Post ob开发者_高级运维jects. Each Post has an IntegerField that gets incremented whenever a certain link is clicked. When that link is clicked, I set a cookie to indicate that it has been clicked and prevent the user from clicking it again. Thus the cookie will look like so:

is_clicked=[1,2,3,4,5]

where the integers 1,2,3,4,5 are Post.id.

Should I do this using context processor, middleware, or something else?

Thanks!


Middleware. Specifically, the session middleware.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号