# Sécurité Django (Django) > CSRF protection, XSS prevention, SQL injection, clickjacking, HTTPS, security middleware, best practices - 22 questions d'entretien - Confirmé - [Questions d'entretien: Django](https://sharpskill.dev/fr/technologies/django/questions-entretien.md) ## 1. Quel est le rôle principal du token CSRF dans Django ? **Réponse** Le token CSRF (Cross-Site Request Forgery) protège contre les attaques où un site malveillant envoie des requêtes au nom d'un utilisateur authentifié. Django génère un token unique par session et vérifie sa présence dans les formulaires POST. Cela empêche les attaquants de forger des requêtes car ils ne peuvent pas deviner ce token aléatoire. ## 2. Comment inclure le token CSRF dans un formulaire Django ? **Réponse** La template tag csrf_token génère automatiquement un champ hidden contenant le token CSRF. Elle doit être placée à l'intérieur de la balise form pour les requêtes POST. Django vérifie ensuite ce token via le middleware CsrfViewMiddleware. Sans cette tag, le formulaire sera rejeté avec une erreur 403 Forbidden. ## 3. Quel décorateur permet d'exempter une vue de la vérification CSRF ? **Réponse** Le décorateur csrf_exempt désactive la protection CSRF pour une vue spécifique. Il est utile pour les endpoints API externes qui ne peuvent pas fournir de token CSRF. Cependant, son utilisation doit être limitée car elle expose la vue aux attaques CSRF. Pour les APIs, il est préférable d'utiliser une authentification par token. ## 19 questions supplémentaires disponibles - Comment Django protège-t-il automatiquement contre les attaques XSS dans les templates ? - Quel filtre de template permet d'afficher du contenu HTML non échappé dans Django ? S'inscrire gratuitement: https://sharpskill.dev/fr/login ## Autres sujets d'entretien Django - [Les bases de Python](https://sharpskill.dev/fr/technologies/django/questions-entretien/python-basics.md): 25 questions, Junior - [Python orienté objet](https://sharpskill.dev/fr/technologies/django/questions-entretien/python-oop.md): 20 questions, Junior - [Fondamentaux Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-fundamentals.md): 20 questions, Junior - [Models Django - Bases](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-models-basics.md): 22 questions, Junior - [Vues Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-views.md): 20 questions, Junior - [Templates Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-templates.md): 18 questions, Junior - [Formulaires Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-forms.md): 22 questions, Confirmé - [QuerySets avancés](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-querysets.md): 25 questions, Confirmé - [Authentification Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-authentication.md): 22 questions, Confirmé - [Middleware Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-middleware.md): 18 questions, Confirmé - [Admin Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-admin.md): 20 questions, Confirmé - [Django REST Framework](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-rest-framework.md): 30 questions, Confirmé - [Signaux Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-signals.md): 18 questions, Confirmé - [Upload de fichiers](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-file-upload.md): 20 questions, Confirmé - [Cache Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-caching.md): 20 questions, Confirmé - [Sessions Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-sessions.md): 18 questions, Confirmé - [Email Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-email.md): 18 questions, Confirmé - [Tests Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-testing.md): 22 questions, Confirmé - [Déploiement Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-deployment.md): 24 questions, Confirmé - [ORM Django avancé](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-orm-advanced.md): 28 questions, Senior - [Performance Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-performance.md): 24 questions, Senior - [Django & Celery](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-celery.md): 22 questions, Senior - [Django Channels](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-channels.md): 24 questions, Senior - [Django & GraphQL](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-graphql.md): 24 questions, Senior - [Django & Docker](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-docker.md): 20 questions, Senior - [Django dans un écosystème Microservices](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-microservices.md): 24 questions, Senior - [Commandes Django personnalisées](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-custom-commands.md): 18 questions, Senior - [Internationalisation Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-internationalization.md): 20 questions, Senior - [Design Patterns Django](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-design-patterns.md): 24 questions, Senior - [Django Async & ASGI](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-async-asgi.md): 26 questions, Senior - [Settings & Configuration Production](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-settings-configuration.md): 22 questions, Senior - [Observabilité & Monitoring](https://sharpskill.dev/fr/technologies/django/questions-entretien/django-observability.md): 24 questions, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/fr/technologies/django/questions-entretien/django-security