before you mark this as duplicate please read through as i have gone through lots of stack overflow questions but could not find a suitable solution.

So the problem i am facing is i am new to django and learnt about CSRF protection for POST requests. I have successfully implemented these calls on a non-ajax based page. But the current project that i am working on is a one page application. So all the calls are through ajax and in vanila JS not using any library. The problem that i am facing with is that for the first request i get the valid CSRF token that i generated in the template. But after the first ajax call the CSRF token changes. So i want to know what is the right method in django for a situation like this. Should i make all request respond with CSRF token somehow and save them in a JS variable?

Also currently there are two pages. The first is a simple login template which has no ajax calls . It posts to the home page with credentials and if valid it is done. But inside the home there are multiple forms. And submitting any one of them changes the token so how do i handle a situation like this.

PS: i prefer the codes in pure JS not jquery or any other framework and would not want to disable to csrf protection.

I already though of storing the CSRF token in cookie or session variable by that would be defeating the whole purpose of token.

Please if you could attach a sample code that i can learn from.