After utilizing JavaScript to create a form element, I encountered an issue while trying to submit the form. The error message received was:
Forbidden (403)
CSRF verification failed. Request aborted.
The purpose behind creating this form element with JavaScript is to update the user page using AJAX. Here is the code for the created form element:
var tagform = document.createElemenet('form')
var tagbutton = document.createElemenet('button')
tagform.setAttribute('method', 'post');
tagform.setAttribute('action', '/businesshub/comment_delete/');
tagbutton.setAttribute('type', 'submit');
tagform.appendChild(tagbutton);
I am working with Django and now need to add {% csrf_token %} to my form element that was created using JavaScript. Does anyone have suggestions on how to implement this? Thank you.