I want to check if csrf tokens work on my django site. The problem is that csrf_token returns the value of the token, not the custom value of 'csrftoken'. Is there a way to set the csrf value for testing? This is the code I'm working with:
token = 'csrftoken'
client = Client(enforce_csrf_checks=True)
client.login(username='user', password='pass')
client.get("/my/web/page/")
csrf_token = client.cookies[token].value
assetEqual(token, csrf_token)
source
share