[Answer]-Ajax post to Django view CSRF forbidden

0👍

Solution:

Empty your browser cache. The above code is correct.

1👍

In your question you’re missing the template tag {{ csrf_token }} in your template.

From the docs:

If your view is not rendering a template containing the csrf_token template tag, Django might not set the CSRF token cookie. This is common in cases where forms are dynamically added to the page. To address this case, Django provides a view decorator which forces setting of the cookie: ensure_csrf_cookie().

Leave a comment