如何自定义Django-allauth和模板?

yptwkmov  于 2023-10-21  发布在  Go
关注(0)|答案(1)|浏览(113)

有关于如何自定义django-allauth模板和字段的教程吗?我知道如何使用现有的allauth和添加字段。但我想了解有关自定义模板完全像改变秩序和其他?

ff29svar

ff29svar1#

如果在代码布局中创建一个具有此名称的文件templates/account/login.html,它可以覆盖django-allauth附带的文件。
对于社交帐户templates/**socialaccount**/connections.html
Django-Allauth有一些文档可以覆盖模板。

重新排序表单的选项之一

# yourapp/forms.py
from allauth.account.forms import SignupForm
class YourSignupForm(SignupForm):
    field_order = ['email', 'username', 'password1', 'password2']

# settings.py:
ACCOUNT_FORMS = {'signup': 'mysite.forms.YourSignupForm'}

一些示例手动呈现字段

<div class="fieldWrapper">
    {{ form.email.errors }}
    <label for="{{ form.email.id_for_label }}">Your email address:</label>
    {{ form.email }}
</div>
<div class="fieldWrapper">
    {{ form.username.errors }}
    <label for="{{ form.username.id_for_label }}">Your Username:</label>
    {{ form.username }}
</div>
<div class="fieldWrapper">
    {{ form.password1.errors }}
    <label for="{{ form.password1.id_for_label }}">Password:</label>
    {{ form.password1 }}
</div>
<div class="fieldWrapper">
    {{ form.password2.errors }}
    <label for="{{ form.password2.id_for_label }}">Password(again):</label>
    {{ form.password2 }}
</div>

验证码:

from allauth.account.forms import SignupForm
class MyCustomSignupForm(SignupForm):
    first_name = forms.CharField(max_length=100) 
    last_name = forms.CharField(max_length=100)

    def save(self, request):

        user = super(MyCustomSignupForm, self).save(request)

        return user

settings.py:

ACCOUNT_FORMS = {'signup': 'mysite.forms.MyCustomSignupForm'}

相关问题