Django adding placeholders to django built in login forms

后端 未结 5 595
灰色年华
灰色年华 2021-01-06 03:13

I\'m using django built-in login forms and i want to add placeholders to username and password.

My template:

<
5条回答
  •  佛祖请我去吃肉
    2021-01-06 03:49

    You can add another filter

    @register.filter(name="add_place_holder")
    def add_place_holder(field, place_holder=None):
        if place_holder == None:
            return field
        else:
            field.field.widget.attrs.update({'placeholder': place_holder})
            return field
    

提交回复
热议问题