使用 django-registration 在 Django 1.2 中禁用电子邮件样式的用户名
Django 1.2 允许用户名采用电子邮件地址的形式。
Django 1.2 中的更改:用户名可能 现在包含@、+、.和 - 字符
我知道这是一个非常需要的功能,但是如果您不想要新的行为怎么办?它会在配置文件 URL 中产生混乱的用户名,并且似乎会破坏 django 注册(如果用户使用电子邮件样式的用户名注册帐户,则 django 注册激活电子邮件中的链接将返回 404)。
有谁有恢复旧行为并禁用电子邮件式用户名的方法吗?
Django 1.2 allows usernames to take the form of an email address.
Changed in Django 1.2: Usernames may
now contain @, +, . and - characters
I know that's a much-requested feature, but what if you don't want the new behavior? It makes for messy usernames in profile URLs and seems to break django-registration (if a user registers an account with an email-style username, the link in the django-registration activation email returns 404).
Does anyone have a recipe for restoring the old behavior and disabling email-style usernames?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有直接的方法可以恢复到旧的行为。
处理此问题的最简单方法是根据您的需求强制对用户名进行客户端和服务器端验证。 django-registration 不是一个积极开发的组件,我不会指望来自该方向的任何内容。只需在您这边添加一些额外的验证即可。
引用 Jacob 关于此事:
There is no straightforward way to revert back to old behavior.
The easiest way to handle this would be to enforce client and server side validation of usernames according to your demands. django-registration is not an actively developed component, I wouldn't count on anything coming from that direction. Just add some extra validation on your side.
To quote Jacob on this matter:
django-registration 实际上不是这里的问题。问题是我已经对其 RegistrationForm 进行了子类化,使用新的 help_text 重新定义了用户名字段。通过这样做,我阻止了它使用自己的正则表达式字段。为了解决这个问题,我必须将一些零散的内容从 RegistrationForm 中提取到我的EnhancedRegistrationForm 子类中。
请注意正则表达式行,它反映了旧式用户名字符限制(这就是我想要的)。
django-registration actually wasn't the problem here. The problem was that I had subclassed its RegistrationForm, redefining the username field with new help_text. In so doing, I had prevented it from using its own regex field. To fix this, I had to pull a few bits and pieces from RegistrationForm into my EnhancedRegistrationForm subclass.
Note the regex line, which mirrors the old-style username character restrictions (which is what I want).