签出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