2013-04-05 2 views
3

django에 로그인보기가 내장 된 AuthenticationForm을 표시하기 위해 django-crispy-forms를 사용하려고합니다. AuthenticationForm을 서브 클래 싱하는 데 문제가 있습니다. AttributeError가 발생합니다. 이 오류는 다음 'WSGIrequest' object has no attribute 'get'.를 말한다 내 양식입니다 :이 오류가 로그인 뷰가 리디렉션 (필자는 @login_required 장식을 사용하고 있습니다)에서 얻을 통해 호출되는과 관련이있다 생각Django-crispy-forms AttributeError 내장 된 AuthenticationForm

class LoginForm(AuthenticationForm): 
    def __init__(self, *args, **kwargs): 
     self.helper = FormHelper() 
     self.helper.form_tag = False 
     self.helper.layout = Layout(
      Field('username', placeholder="username"), 
      Field('password', placeholder="password"),) 
     super(AuthenticationForm, self).__init__(*args, **kwargs) 

. 누구든지 django-crispy-forms를 사용하여 양식을 서브 클래 싱하고이 오류를 피하는 방법에 대한 아이디어가 있습니까? 당신이 양식에 오류가있어 같은

답변

7

것 같습니다 : 부모 클래스 AuthenticationForm하지 LoginForm을 통과

class LoginForm(AuthenticationForm): 
    def __init__(self, *args, **kwargs): 
     super(LoginForm, self).__init__(*args, **kwargs) 
     self.helper = FormHelper() 
     self.helper.form_tag = False 
     self.helper.layout = Layout(
      Field('username', placeholder="username"), 
      Field('password', placeholder="password"), 
     ) 

당신은 슈퍼를 요구하고있다.

+0

나는 내가 간과하고 있었던 무엇인가 단순 할 예정였다라는 것을 알고 있었다! 그것을 잡아 주셔서 감사합니다 ... 내 두통은 이제 사라졌습니다 :-) – bgmaster

+0

다행 그것은 당신을 :) BTW, 일반적으로 가능한 빨리 부모 메서드를 호출하는 것이 좋습니다. crispy-forms 문서가 업데이트되었습니다. – maraujop