覆盖django allauth中的表单

时间:2016-05-19 10:15:17

标签: django-forms override django-authentication django-allauth

我在Django建立一个项目,我使用django-allauth进行社交认证,但我已经建立了自己的认证系统。
现在,正如我所说,我只是想使用django-allauth进行社交认证,但不是经典认证,因为 - 我已经尝试过 - 它的认证系统与我自己的认证系统发生冲突。

我尝试通过创建如下所示的FormView来覆盖表单:

class LoginUser(FormView):
    template_name = 'account/login.html'
    form_class = MyLoginForm

调用此表单:

class MyLoginForm(forms.ModelForm):
    """
    A form that login a user.
    """

    email = forms.EmailField(label='', required=True, widget = forms.TextInput(
        attrs = {
            'placeholder': 'DIOCAAAAA',
            'class': 'form-control',
            'id': 'login-email'
        }
    ))

    password1 = forms.CharField(label='', required=True, widget=forms.PasswordInput(attrs = {
            'placeholder': 'Password',
            'class': 'form-control',
            'id': 'login-password',
            'data-parsley-trigger': 'focusout'
        }
    ))

    class Meta:
        model = CustomUser
        fields = ('email',)

我已经在网址中添加了这个内容:

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('allauth.urls')),
    **url(r'^accounts/login/$', views.LoginUser.as_view()),**
    [...]
)

但是我收到了这个错误:

  

/ accounts / login /
的TypeError    init ()获得了意外的关键字参数' request'

我是朝着正确的方向前进,还是应该尝试其他方式?

1 个答案:

答案 0 :(得分:0)

尝试将您的网址更改为不同的位置,我认为您的网址与allauth网址冲突,因为allauth已经有了这个

function isTightTwins(s){
  var n = s.length,
      char_idxs = {};

  for (var i=0; i<n; i++){
    if (char_idxs[s[i]] == undefined){
      char_idxs[s[i]] = [i];
    } else {
      char_idxs[s[i]].push(i);
    }
  }

  var duplicates = new Set();

  for (var i in char_idxs){

    // character with odd count
    if (char_idxs[i].length & 1){
      return false;
    }

    if (char_idxs[i].length > 2){
      for (let j of char_idxs[i]){
        duplicates.add(j);
      }      
    }
  }

  function f(i,j,js){

    // base case positive
    if (js.size == n/2 && j == n){
      return true;
    }

    // base case negative
    if (j > n || (n - j < n/2 - js.size)){
      return false;
    }

    // i is not less than j
    if (i >= j) {
      return f(i,j + 1,js);
    }

    // this i is in the list of js
    if (js.has(i)){
      return f(i + 1,j,js);

    // yet to find twin, no match
    } else if (s[i] != s[j]){
      return f(i,j + 1,js);

    } else { 

      // maybe it's a twin and maybe it's a duplicate
      if (duplicates.has(j)) {
        var _js = new Set(js);
        _js.add(j);
        return f(i,j + 1,js) | f(i + 1,j + 1,_js);          

      // it's a twin
      } else {
        js.add(j);
        return f(i + 1,j + 1,js);
      }
    }
  }

  return f(0,1,new Set());
}

console.log(isTightTwins("1213213515")); //  true
console.log(isTightTwins("11222332")); // false