Enable CSRF Protection in Forms
A snippet showing how to add CSRF protection in forms.
<!-- template.html -->
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Explanation:
- CSRF token is added as hidden input to protect against CSRF attacks.
- Category Security
- Total Views 696
- Last Modified 21 February, 2026
- Tags #security #csrf #forms #protection
Previous snippet
Content-Type Enforcement Middleware
Next snippet