Django

Django Authentication

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

22 câu hỏi phỏng vấn·
Mid-Level
1

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

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững Django cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí