django-allauth: rearrange form fields (change order)

…衆ロ難τιáo~ 提交于 2019-12-04 09:02:46

You need to provide the field_order attribute:

class UserProfileForm(forms.ModelForm):
    class Meta:
        model = UserProfile
        fields = ('gender', 'country', 'city', 'birth_date', 'has_accepted_tos')
        field_order = ['username', 'email', 'password1', 'password2', 'gender', 'country']

However, a better practice would be to use the template file to render the form exactly as you want to.

Quoting the project author:

(...) Then again, I would not put too much weight on what allauth has to offer out of the box display/design wise. All of this is just for reference, the idea is that you create a proper design & form layout in your templates.

References:

[1] https://github.com/pennersr/django-allauth/blob/master/allauth/account/forms.py

[2] https://github.com/pennersr/django-allauth/issues/269

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