LoginSignup
11
6

More than 5 years have passed since last update.

Djangoで入力フィールドにプレースホルダ(placeholder)を設定する

Posted at

Django:1.10

以下に記載されていました。

Widgets | Django documentation | Django
https://docs.djangoproject.com/ja/1.10/ref/forms/widgets/#customizing-widget-instances

なるほど、attrsに指定したらいけそう。

forms.py
class LoginForm(forms.Form):
    username = forms.CharField(label='LOGIN_ID', max_length=30,
            widget=forms.TextInput(
            attrs={'placeholder':'ユーザ名', 'class':'class_name'}))
    password = forms.CharField(
            label='PASSWORD', max_length=128,
            widget=forms.PasswordInput(
            attrs={'placeholder':'パスワード', 'class':'class_name'}))

プレースホルダが表示されました。

無題.png

11
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
6