UserCreationFormによる登録
ユーザーが安全にサインアップできるようにします
「UserCreationFormによる登録」はCoddyKit上の無料Django Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDjango Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Django Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Let People Sign Up
Login assumes accounts already exist. To let visitors create their own, you need a registration view backed by a sign-up form. ✍️
Meet UserCreationForm
Django gives you UserCreationForm, a ready form with username and two password fields that creates a User on save.
from django.contrib.auth.forms import UserCreationFormBuilt-In Password Checks
The form confirms the two passwords match and runs Django's strength validators, so weak or mismatched passwords are rejected automatically.
Show the Form on GET
On a GET request, create an empty form and render it. This is the blank sign-up page the visitor first sees.
form = UserCreationForm()
return render(request, "signup.html", {"form": form})Bind Data on POST
On a POST, build the form with request.POST so it holds the submitted values, ready to validate.
form = UserCreationForm(request.POST)Validate Then Save
Call is_valid(); if it passes, form.save() inserts the new user with a properly hashed password. One line creates the account.
if form.is_valid():
user = form.save()Log Them In Right Away
A smooth flow signs the user in immediately after sign-up. Call login() with the saved user so they skip a second step.
user = form.save()
login(request, user)Render the Errors
When validation fails, just render the same form again. It carries error messages that tell the user exactly what to fix.
The Sign-Up Template
Your template wraps the form in a POST and adds csrf_token. Output the fields and a submit button to finish the page.
Extending the Form
Need an email field? Subclass UserCreationForm and add it. The built-in form keeps things minimal until you ask for more.
Redirect After Success
Finish by sending the new user somewhere useful with a redirect, like their dashboard, instead of re-rendering the form.
return redirect("dashboard")Quick Check
What does UserCreationForm verify about the password automatically?
Recap: Registration
You used UserCreationForm to validate sign-ups, saved the new user with a hashed password, and logged them in right away. ✅
よくある質問
「UserCreationFormによる登録」レッスンは無料ですか?
はい。「UserCreationFormによる登録」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Django Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Django Academyコースには全4レッスンが含まれています。
「UserCreationFormによる登録」で何を学びますか?
ユーザーが安全にサインアップできるようにします ブラウザで直接実行するハンズオンコードでDjango Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Django Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのDjango Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「UserCreationFormによる登録」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このDjango Academyレッスンでコードを書いて実行できますか?
はい。すべてのDjango Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Userモデルとauthenticate()
- login、logout、Auth Views
- UserCreationFormによる登録
- login_requiredとビューの保護