CSRF를 이용하여 시스템을 보호하는 것이 완전하지는 않지만 해주어야 하는군요.
<form method="post"> {% csrf_token %} <input type="text" name="username"> <button type="submit">Submit</button> </form>
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
const csrftoken = getCookie('csrftoken');