... ルドに別のウィジェットを使用したい場合は、フィールド定義で widget 引数を使用できます。例えば: from django import forms class CommentForm ( forms . Form ): name = forms . CharField () url = forms . URLField () comment = forms . CharField ( widget = forms . Tex ... S ファイルにいくつか記述を追加する必要もあります)。 たとえば、以下のフォームを取り上げます: from django import forms class CommentForm ( forms . Form ): name = forms . CharField () url = forms . URLField () comment = forms . CharField () このフォームには、名 ... put ウィジェットが含まれます。それぞれにはデフォルトのレンダリングが適用され、CSS クラスや追加の属性はありません。 >>> f = CommentForm ( auto_id = False ) >>> print ( f ) <div>Name:<input type="text" name="name" required></div> <div>Url:<input type="url" na ... ... 装する Form の完全な例です。出力を簡略化するために、 auto_id=False を指定しています: >>> from django import forms >>> class CommentForm ( forms . Form ): ... name = forms . CharField ( label = "Your name" ) ... url = forms . URLField ( label = "Your website" ... , required = False ) ... comment = forms . CharField () ... >>> f = CommentForm ( auto_id = False ) >>> print ( f ) <div>Your name:<input type="text" name="name" required></div> <div>Your website:<input ... 、あるフィールドが特定の値で初期化された「空」のフォームを表示したい場合です。例えば: >>> from django import forms >>> class CommentForm ( forms . Form ): ... name = forms . CharField ( initial = "Your name" ) ... url = forms . URLField ( initial = "https://" ... ... ルドに別のウィジェットを使用したい場合は、フィールド定義で widget 引数を使用できます。例えば: from django import forms class CommentForm ( forms . Form ): name = forms . CharField () url = forms . URLField () comment = forms . CharField ( widget = forms . Tex ... S ファイルにいくつか記述を追加する必要もあります)。 たとえば、以下のフォームを取り上げます: from django import forms class CommentForm ( forms . Form ): name = forms . CharField () url = forms . URLField () comment = forms . CharField () このフォームには、名 ... put ウィジェットが含まれます。それぞれにはデフォルトのレンダリングが適用され、CSS クラスや追加の属性はありません。 >>> f = CommentForm ( auto_id = False ) >>> print ( f ) <div>Name:<input type="text" name="name" required></div> <div>Url:<input type="url" na ... ... 装する Form の完全な例です。出力を簡略化するために、 auto_id=False を指定しています: >>> from django import forms >>> class CommentForm ( forms . Form ): ... name = forms . CharField ( label = "Your name" ) ... url = forms . URLField ( label = "Your website" ... , required = False ) ... comment = forms . CharField () ... >>> f = CommentForm ( auto_id = False ) >>> print ( f ) <div>Your name:<input type="text" name="name" required></div> <div>Your website:<input ... 、あるフィールドが特定の値で初期化された「空」のフォームを表示したい場合です。例えば: >>> from django import forms >>> class CommentForm ( forms . Form ): ... name = forms . CharField ( initial = "Your name" ) ... url = forms . URLField ( initial = "https://" ... ... ドレベルとフォームインスタンスレベルの両方で initial が提供され、後者が優先されます。 >>> from django import forms >>> class CommentForm ( forms . Form ): ... name = forms . CharField ( initial = "class" ) ... url = forms . URLField () ... comment = forms . C ... harField () ... >>> f = CommentForm ( initial = { "name" : "instance" }, auto_id = False ) >>> print ( f ) <div>Name:<input type="text" name="name" value="ins ... en dealing with callables whose return values can change (e.g. datetime.now or uuid.uuid4 ): >>> import uuid >>> class UUIDCommentForm ( CommentForm ): ... identifier = forms . UUIDField ( initial = uuid . uuid4 ) ... >>> f = UUIDCommentForm () >>> f . get_ ... ... ドレベルとフォームインスタンスレベルの両方で initial が提供され、後者が優先されます。 >>> from django import forms >>> class CommentForm ( forms . Form ): ... name = forms . CharField ( initial = "class" ) ... url = forms . URLField () ... comment = forms . C ... harField () ... >>> f = CommentForm ( initial = { "name" : "instance" }, auto_id = False ) >>> print ( f ) <div>Name:<input type="text" name="name" value="ins ... en dealing with callables whose return values can change (e.g. datetime.now or uuid.uuid4 ): >>> import uuid >>> class UUIDCommentForm ( CommentForm ): ... identifier = forms . UUIDField ( initial = uuid . uuid4 ) ... >>> f = UUIDCommentForm () >>> f . get_ ... 2026年10月08日