2014-01-15 54 views
0

我編寫自定義註冊視圖的原因是重寫django-allauth SignupView的form_valid(),並按照上述操作。啓用以覆蓋django-allauth UserSignupView

出於某種原因,當我點擊註冊按鈕時,控件不會進入CustomSignupView,而是進入allauth UserSignup視圖的form_valid()並執行該操作。 請幫助我如何訪問CustomSignUpView。 這是我實現

views.py:

from allauth.account.views import LoginView, SignupView 

from allauth.account.forms import SignupForm 

from .forms import CustomLoginForm 

from .notify import Notification 

class CustomSignupView(SignupView): 

    notify = Notification() 

    def __init__(self, **kwargs): 

     super(CustomSignupView, self).__init__(*kwargs) 
     self.form_class = SignupForm 

    def send_email(self, form): # custom implementation 
     self.notify.notify(self.entity_type, form.cleaned_data) 


    def form_valid(self, form): 

     self.send_email(form) 
     return super(CustomSignupView, self).form_valid(form) 

這是Django的實現:

class SignupView(RedirectAuthenticatedUserMixin, CloseableSignupMixin, 
      FormView): 
    template_name = "account/signup.html" 
    form_class = SignupForm 
    redirect_field_name = "next" 
    success_url = None 

def get_success_url(self): 
    # Explicitly passed ?next= URL takes precedence 
    ret = (get_next_redirect_url(self.request, 
           self.redirect_field_name) 
      or self.success_url) 
    return ret 

def form_valid(self, form): 
    import pdb; pdb.set_trace() 
    user = form.save(self.request) 
    return complete_signup(self.request, user, 
          app_settings.EMAIL_VERIFICATION, 
          self.get_success_url()) 
+0

你的問題是什麼? – CrazyCasta

+0

請看我只是想發送電子郵件通知給form_valid的管理員,表示新用戶已經註冊了我們的網站。 通過超過allauth意見。 –

+2

是的,但你的問題是什麼?你有問題嗎? – CrazyCasta

回答

2

我相信你正在使用基於類的意見,所以你應該實現一個form_valid方法:

class CustomSignupView(SignupView): 

    def __init__(self, **kwargs): 
     super(CustomSignupView, self).__init__(*kwargs) 
     self.form_class = CustomSignupForm 

    def send_email(self, form): # custom implementation 
     self.notify.notify(self.entity_type, form.cleaned_data) 

    def form_invalid(self, form): 
     #show some error etc 
     pass 

    def form_valid(self, form): 
     self.send_email(form) 
     return super(CustomSignupView, self).form_valid(form) 

不知道這是什麼你試試t o實現

+0

我找到了所需的解決方案。我的網址沒有正確定義。感謝所有幫助的人。 –