0Pricing
Django Academy · Lektion

Das User-Model und authenticate()

Zugangsdaten mit dem integrierten User überprüfen

Das User-Model und authenticate() ist eine kostenlose Django Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Django Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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. ✅

Häufig gestellte Fragen

Ist die Lektion „Das User-Model und authenticate()“ kostenlos?

Ja — der vollständige Text von „Das User-Model und authenticate()“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Django Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Das User-Model und authenticate()“?

Zugangsdaten mit dem integrierten User überprüfen Du übst Django Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Django Academy zu starten?

Keine Vorkenntnisse erforderlich. Django Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „Das User-Model und authenticate()“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Django Academy-Lektion Code schreiben und ausführen?

Ja. Jede Django Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Das User-Model und authenticate()
  2. login, logout und Auth-Views
  3. Registrierung mit UserCreationForm
  4. login_required und Views schützen
← Zurück zu Django Academy