override django-allauth default forms

后端 未结 2 1310
走了就别回头了
走了就别回头了 2021-02-04 19:42

I want to override the default forms of django-allauth in order to change\\add default widget attributes, class variables without changing the initial code of allauth form. How

2条回答
  •  太阳男子
    2021-02-04 20:07

    You can override any (or all) of the allauth default templates by creating your own tree of template files.

    The naming of the hierarchy must match allauth, e.g. this is from my project:

    allauthdemo/templates/
    ├── allauth
    │   ├── account
    │   └── socialaccount
    ├── my
    ├── other
    ├── template
    └── dirs
    

    The template settings in settings.py must include those dirs, e.g.:

    TEMPLATES = [
        {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'allauthdemo', 'templates', 'allauth'),
            os.path.join(BASE_DIR, 'allauthdemo', 'templates'),
        ],
        ...
    

    This allauth demo on github shows how to do it. Disclaimer: I wrote that demo.

提交回复
热议问题