我想允许我的用户使用希腊字符进行注册。
我在admin.py文件中添加了以下代码。正则表达式是否正确(regex=r'^[\w\p{Greek}-]+$',
)?我想允许希腊语和英语字符
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
class MyUserCreationForm(UserCreationForm):
username = forms.RegexField(
label='Username',
max_length=30,
regex=r'^[\w\p{Greek}-]+$',
help_text = 'Required. 30 characters or fewer. Alphanumeric characters only (letters, digits, hyphens and underscores).',
error_message = 'This value must contain only letters, numbers, hyphens and underscores.')
class MyUserChangeForm(UserChangeForm):
username = forms.RegexField(
label='Username',
max_length=30,
regex=r'^[\w\p{Greek}-]+$',
help_text = 'Required. 30 characters or fewer. Alphanumeric characters only (letters, digits, hyphens and underscores).',
error_message = 'This value must contain only letters, numbers, hyphens and underscores.')
class MyUserAdmin(UserAdmin):
form = MyUserChangeForm
add_form = MyUserCreationForm
admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)