0Pricing
Django Academy · レッスン

Userモデルとauthenticate()

組み込みユーザーで認証情報を検証します

「Userモデルとauthenticate()」はCoddyKit上の無料Django Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDjango Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Django Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

You Already Have Users

Django ships a full User model out of the box, so you never write account tables by hand. It stores usernames, hashed passwords, and more. 👤

Where the User Lives

The model sits in django.contrib.auth, an app that is enabled in fresh projects. Import it and the whole auth toolkit comes along.

from django.contrib.auth.models import User

Key User Fields

Each user has a username, plus email, first_name, and last_name. These are the everyday fields you read and display in your app.

Passwords Are Never Plain

Django stores a salted hash of every password, never the raw text. Even you, the developer, cannot read a user's actual password. 🔒

Create a User Safely

Use create_user so the password gets hashed for you. Setting the password by hand would store it in the clear.

User.objects.create_user(username="ada", password="secret123")

Meet authenticate()

The authenticate() function checks a username and password against the database for you. It is the heart of every login flow.

from django.contrib.auth import authenticate

How authenticate() Works

Pass it the credentials and it returns the matching user object when they are correct. No hashing or lookups for you to write.

user = authenticate(username="ada", password="secret123")

When Credentials Fail

If the username or password is wrong, authenticate() returns None. Always check for that before treating the user as logged in.

if user is None:
    print("Invalid credentials")

Active Users Only

The is_active flag lets you disable accounts. By default authenticate() refuses to return inactive users, blocking banned logins.

Staff and Superusers

Two extra flags matter: is_staff grants admin-site access, and is_superuser grants every permission. Most users have neither.

Authenticate Is Not Login

Remember: authenticate() only verifies identity. It does not start a session, so the user is not yet logged in after this call.

Quick Check

What does authenticate() return when the password is wrong?

Recap: Users and Identity

You met Django's built-in User model and used authenticate() to verify credentials. Passwords stay hashed, and a failed check gives None. ✅

よくある質問

「Userモデルとauthenticate()」レッスンは無料ですか?

はい。「Userモデルとauthenticate()」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Django Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Django Academyコースには全4レッスンが含まれています。

「Userモデルとauthenticate()」で何を学びますか?

組み込みユーザーで認証情報を検証します ブラウザで直接実行するハンズオンコードでDjango Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Django Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDjango Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「Userモデルとauthenticate()」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDjango Academyレッスンでコードを書いて実行できますか?

はい。すべてのDjango Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Userモデルとauthenticate()
  2. login、logout、Auth Views
  3. UserCreationFormによる登録
  4. login_requiredとビューの保護
← Django Academyに戻る