How to make django-registration use my customized UserCreationForm and UserChangeForm?

落花浮王杯 提交于 2019-12-01 10:35:21

问题


I am developing a website using Django 1.4 and django-registration

I would like to allow users to create their user names using arbitrary Unicode characters. Currently, if someone tries to register using non-latin characters, he will see an error message. The code responsible for rejecting this kind of non-ASCII usernames is in UserCreationForm and UserChangeForm, see here:

username = forms.RegexField(
        label=_("Username"), max_length=30, regex=r"^[\w.@+-]+$",
        help_text = _("Required. 30 characters or fewer. Letters, digits and "
                      "@/./+/-/_ only."),
        error_messages = {
            'invalid': _("This value may contain only letters, numbers and "
                         "@/./+/-/_ characters.")})

Now, I would like to change it. I've seen some suggestions that I should create my own UserCreationForm, and creating a derived class with some changed behaviour seems easy enough.

The bit I don't understand is: how to make django-registration use my customized UserCreationForm and UserChangeForm? Obviously, I would like to avoid modifying the source of django-registration, if at all possible.


回答1:


See http://docs.b-list.org/django-registration/0.8/views.html

After creating your own registration form you can pass this form to the register view of django-registration. Look for the registration.backends.default.urls module

url(r'^register/$', register,
     {'backend': 'registration.backends.default.DefaultBackend', 
     'form_class': MyRegistrationForm},


来源:https://stackoverflow.com/questions/12357168/how-to-make-django-registration-use-my-customized-usercreationform-and-userchang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!