Django

Django Authentication

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

22 面接問題·
Mid-Level
1

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

回答

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?

回答

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?

回答

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 面接問題

次の面接に向けてDjangoをマスター

すべての問題、flashcards、技術テスト、コードレビュー演習、面接シミュレーターにアクセス。

無料で始める