Django Allauth错误:“'socialaccount'不是注册标记库”

时间:2016-03-03 20:34:29

标签: python django django-allauth

我按照{strong> django-allauth 的说明进行操作,如here所示。我对使用社交认证不感兴趣 - 只需一个简单的电子邮件和密码注册流程。出于某种原因,当我转到/accounts/login/时,我收到了错误

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

enter image description here

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'

我哪里出错了?

3 个答案:

答案 0 :(得分:5)

您需要将allauth.socialaccount添加到INSTALLED_APPS

有关详情,请参阅settings documentation

答案 1 :(得分:1)

您需要将allauth.socialaccount添加到INSTALLED_APPS或覆盖login.html模板,而不是包含' socialaccount'标签

答案 2 :(得分:0)

对于以后有相同错误的任何人。

如果您看到这样的错误,将会有些情况

'socialaccount' is not a registered tag library. Must be one of:
 accounts
 account_tags
 ....
  1. 如果您已在模板中导入{% load socialaccount %}。例如。登录{。{1}}中未包含allauth.socialaccounts的login.html
  2. 或者您没有INSTALLED_APPS或没有makemigrations。您已经进行了迁移并迁移了

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