繁体   English   中英

Django Allauth 错误:“'socialaccount' 不是已注册的标签库”

[英]Django Allauth Error: "'socialaccount' is not a registered tag library"

我正在按照此处所示的使用django-allauth的说明进行操作。 我对使用社交身份验证不感兴趣 - 只是一个简单的电子邮件和密码注册流程。 出于某种原因,当我去/accounts/login/我收到错误

TemplateSyntaxError at /accounts/login/
'socialaccount' is not a registered tag library. Must be one of:
account
account_tags
...

在此处输入图片说明

在我的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',
            ],
        },
    },
]


# Required by allauth
AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',

    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',
)


# Application definition
INSTALLED_APPS = [
    # My apps
    'trinalysis_app.apps.TrinalysisAppConfig',

    # Third party apps
    'django.contrib.sites', # Django app required for using allauth
    'allauth',
    'allauth.account',

    # Default apps
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

# Set AUTH_USER_MODEL as my own user model that uses the email address as the username 
AUTH_USER_MODEL = 'trinalysis_app.MyUser'


# allauth config params
SITE_ID = 1
LOGIN_REDIRECT_URL = '/'
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'

我哪里做错了?

您需要将allauth.socialaccount添加到INSTALLED_APPS

有关更多信息,请参阅设置文档

您需要将 allauth.socialaccount 添加到 INSTALLED_APPS 或覆盖 login.html 模板并且不包括“socialaccount”标签。

对于将来有相同错误的任何人。

如果你看到这样的错误会有一些条件

'socialaccount' is not a registered tag library. Must be one of:
 accounts
 account_tags
 ....
  1. 如果您在模板中导入了{% load socialaccount %} 例如。 login.html 并且在INSTALLED_APPS不包括allauth.socialaccounts
  2. 或者你没有makemigrations或没有migrate 你已经完成了 makemigrations 并迁移

就我而言,我从 settings.py 中删除了所有 all.auth 但忘记从模板文件中删除{% load socialaccount %} ..但及时解决..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM