CSRF Protection
In Runique forms
When you use {% form.xxx %}, CSRF is included automatically. No need to add it manually.
In manual HTML forms
<form method="post" action="/submit">
{% csrf %}
<input type="text" name="data">
<button type="submit">Send</button>
</form>
For AJAX requests
const csrfToken = document.querySelector('[name="csrf_token"]').value;
fetch('/api/endpoint', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken
},
body: JSON.stringify(data)
});