开发者

Change Form Validation for Admin Login in Django

开发者 https://www.devze.com 2023-01-20 00:58 出处:网络
I use a custom auth backend in my django application that allows users to login with ther emails. But when I try to login in the admin I get the message: \"usernames cant contain the \'@\' char\"

I use a custom auth backend in my django application that allows users to login with ther emails.

But when I try to login in the admin I get the message: "usernames cant contain the '@' char"

I suppose 开发者_如何学编程this error is raised before it reaches the auth backend, so its a form issue, right ?


Unfortunately no, this error is raised just if the authentication fails and there is no User with the given email. The bad thing is that this validation is hard-coded [1].

There is an open ticket for this [2].

Since version 1.2 django allows emails as User.username, if you're using this version maybe you won't even need a custom auth backend. But the bug [2] persists!

The only solution I can see to remove this validation is create a custom AdminSite and override the login() method, which is bad...

[1] http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/sites.py#L323 [2] http://code.djangoproject.com/ticket/13928

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号