I am developing a website using Django 1.4 and I use django-registration for the signup process. It turns out that Unicode characters are not allowed as usernames, whenever a user enters e.g. a Chinese character as part of username the registration fails with:
This value may contain only letters, numbers and @/./+/-/_ characters.
Is it possible to change it so Unicode characters are allowed in usernames? If yes, how can I do it? Also, can it cause any problem?
It is really not a problem - because this character restriction is in UserCreationForm (or RegistrationForm in django-registration) only as I remember, and you can easily make your own since field in database is just normal TextField.
But those restriction is there not without a reason. One of the possible problems I can think of now is creating links - usernames are often used for that and it may cause a problem. There is also bigger possibility of fake accounts with usernames looking the same but being in fact different characters, etc.
Django 1.10 now officially supports unicode usernames, see:
The User model in django.contrib.auth originally only accepted ASCII letters in usernames. Although it wasn’t a deliberate choice, Unicode characters have always been accepted when using Python 3.
The username validator now explicitly accepts Unicode letters by default on Python 3 only. This default behavior can be overridden by changing the username_validator attribute of the User model, or to any proxy of that model, using either ASCIIUsernameValidator or UnicodeUsernameValidator. Custom user models may also use those validators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With