栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

需要Django表单帮助

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

需要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



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/625928.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号