PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 12, 2022

[FIXED] Why does Django caching cause CSRF violation and faulty template rendering?

 November 12, 2022     django, django-cache, django-templates, memcached, python     No comments   

Issue

I am using Django with Memcached in production and as far as I can tell, the caching system seems to work fine, however, it causes certain errors in my application:

  • Whenever a form is submitted, I get a CSRF error, because for some unknown reason the CSRF token gets cached.
  • My templates are also not rendering correctly, for example, when a user is logged in I have a conditional in my template that checks if the user is authenticated, but when viewing the page, the template doesn't get updated and is still showing the cached version.

If anyone knows what is going on here and how I can fix this, please let me know.


Solution

You should fragment cache template, so that you don't cache parts that should be changed with each request



Answered By - iklinac
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing