需要Django表单帮助

需要Django表单帮助,第1张

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



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5631813.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存