您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

需要Django表单帮助

需要Django表单帮助

django注册应用程序。并查看类registration.forms.RegistrationForm及其方法clean_username。

扩展表单以建议一些用户名应该很容易。

这是一些示例代码,用于生成带有编号后缀的唯一用户名

    username # filled with user input or first/lastname etc.

    #check for other profile with equal names (and those with a postfix)
    others = [int(username.replace(name, "0")) 
              for p in User.objects.filter(username__startswith=username).exclude(user=self.user)
              if username.replace(name, "0").isdigit()]

    #do we need a postfix
    if len(others) > 0 and 0 in others:
        username = "%s%d" % (username, max(others) + 1)

您可以在“表单选择”字段中填写生成名称http ://docs.djangoproject.com/en/dev/ref/forms/fields/#choicefield

Go 2022/1/1 18:52:40 有317人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶