【问题标题】:How to over-ride the default templates provided by Django-allauth?如何覆盖 Django-allauth 提供的默认模板?
【发布时间】:2016-06-04 04:22:35
【问题描述】:

我创建了 myapp/templates/account/base.htmlmyapp/templates/account/login.html,所以我认为应该更改模板。但是转到 /account/login 仍然会加载默认模板,而不是我的新模板。那么我该如何真正超越它们呢?

我的 settings.py

中有这个
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',

                # `allauth` needs this from django
                'django.template.context_processors.request',
            ],
        },
    },
]

有什么帮助吗?

【问题讨论】:

    标签: django django-templates django-allauth


    【解决方案1】:

    尝试将您的根目录添加到 DIRS 设置:

    'DIRS': os.path.join(PROJECT_ROOT, 'templates'),
    

    【讨论】:

      【解决方案2】:

      我通过将它们放在我的模板文件夹根目录下的account 和/或socialaccount 中来覆盖它们。可以选择使用名为allauth的父文件夹

      你的结构看起来像:

      • 模板
        • 帐户
        • 社交账号

      • 模板
        • allauth
          • 帐户
          • 社交账号

      原始模板可以在https://github.com/pennersr/django-allauth/tree/master/allauth/templates找到

      【讨论】:

        猜你喜欢
        • 2012-03-15
        • 2019-08-01
        • 2014-01-05
        • 2013-09-18
        • 2019-07-11
        • 2014-08-30
        • 2016-12-24
        • 2016-07-29
        • 2019-01-12
        相关资源
        最近更新 更多