Django

Django Authentication

User model, authentication backend, login/logout, permissions, groups, custom user model

22 perguntas de entrevista·
Mid-Level
1

Which Django model is used by default to represent users in an application?

Resposta

The User model from django.contrib.auth.models is the default model for managing users in Django. It provides essential fields like username, password, email, first_name, last_name, and built-in authentication methods. This model is automatically available after adding django.contrib.auth to INSTALLED_APPS.

2

Which Django function verifies user credentials and returns the corresponding User object?

Resposta

The authenticate() function from django.contrib.auth takes credentials (typically username and password) and verifies them against configured authentication backends. It returns the User object if credentials are valid, or None if authentication fails. This function does not log in the user, it only validates the credentials.

3

Which function creates a session and logs in a user after successful authentication?

Resposta

The login() function from django.contrib.auth takes the request and the authenticated User object to create a session. It stores the user's ID in the session and associates the authentication backend used. This function must be called after authenticate() to complete the login process.

4

How to log out a user and invalidate their session in Django?

5

Which Django decorator restricts view access to logged-in users only?

+19 perguntas de entrevista

Domine Django para sua proxima entrevista

Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.

Comece gratis