zoukankan      html  css  js  c++  java
  • Django-1.10支持中文用户注册登录

    让django 支持中文注册登录,支持中文用户名
    cat django的models文件发现调的如下两个类
    class AbstractUser(AbstractBaseUser, PermissionsMixin):
        """
        An abstract base class implementing a fully featured User model with
        admin-compliant permissions.
    
        Username and password are required. Other fields are optional.
        """
        username_validator = UnicodeUsernameValidator() if six.PY3 else ASCIIUsernameValidator()
    
        username = models.CharField(
            _('username'),
            max_length=150,
            unique=True,
            help_text=_('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'),
            validators=[username_validator],
            error_messages={
                'unique': _("A user with that username already exists."),
            },
        )
    

      

    修改他的正则匹配规则


    [root@localhost auth]# cat validators.py import re from django.core import validators from django.utils import six from django.utils.deconstruct import deconstructible from django.utils.translation import ugettext_lazy as _ @deconstructible class ASCIIUsernameValidator(validators.RegexValidator): #regex = r'^[w.@+-]+$' regex = r'^[S.@+-]+$' message = _( 'Enter a valid username. This value may contain only English letters, ' 'numbers, and @/./+/-/_ characters.' ) flags = re.ASCII if six.PY3 else 0 @deconstructible class UnicodeUsernameValidator(validators.RegexValidator): #regex = r'^[w.@+-]+$' regex = r'^[S.@+-]+$' message = _( 'Enter a valid username. This value may contain only letters, ' 'numbers, and @/./+/-/_ characters.' ) flags = re.UNICODE if six.PY2 else 0 [root@localhost auth]# pwd /usr/local/python27/lib/python2.7/site-packages/django/contrib/auth [root@localhost auth]#

      

  • 相关阅读:
    vs要用报表功能
    汉字与字节
    php 实现excel导入导出
    php 判断是否是手机端和电脑端访问
    php getimagesize image_type_to_extension 等函数不能用
    php 处理base64图片信息
    php 百度编辑器ueditor-dev-1.5.0编译版细节流程
    react 可拖拽改变位置和大小的弹窗
    Java 进制转换
    Java自动装箱测试
  • 原文地址:https://www.cnblogs.com/dribs/p/8376040.html
Copyright © 2011-2022 走看看