Memo/Python

[Django] allauth form field label 지우기

l22hs 2022. 8. 5. 16:17

 

Django allauth 라이브러리를 이용한 로그인 기능을 구현하던 중 못생긴 로그인 페이지를 수정하게 되었다.

부트스트랩 템플릿을 입히는 과정까지는 문제가 없었으나, ID와 PW를 입력하는 TextField에 'Username: '과 'Password: '라는 label이 따로 붙어 마음에 들지 않았다.

 

 

약 한 시간 정도 검색해본 결과 많은 방법들과 코드들이 있었지만 왠지 모르게 잘 적용되지 않았다.

결국 이것 저것 하나씩 해보다 보니 forms.py에 아래와 같은 클래스를 추가하면 몬생긴 label을 지울 수 있었다.

class LoginForm(LoginForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.fields["login"].label = ""
        self.fields["password"].label = ""

 

 

 

Django allauth: Remove form label?

The Problem I'm building a registration page using Django with allauth. I am trying to remove the 'E-mail' label from the email field. What I've tried I've removed the labels from First Name and...

stackoverflow.com