Django 1.9 和 allauth 0.24.1

roa*_*ach 2 python django django-allauth

我有 Django 1.9

我按照此说明安装了 allauth 。但运行迁移后出现以下错误:

./manage.py migrate
Run Code Online (Sandbox Code Playgroud)

错误:

...
RuntimeError: Model class allauth.account.models.EmailAddress doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. 
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题。

Dhi*_*aTN 5

我认为您缺少allauth特定的上下文处理器:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "templates")],
        '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',
                'django.template.context_processors.i18n',
                # Required by allauth template tags
                "django.core.context_processors.request",
                # allauth specific context processors
                "allauth.account.context_processors.account",
                "allauth.socialaccount.context_processors.socialaccount",
            ],
        },
    },
]
Run Code Online (Sandbox Code Playgroud)

Django 站点框架是必需的,但您还应该在以下位置添加 allauth 应用程序INSTALLED_APPS

INSTALLED_APPS = (
    ... # here previous existing apps

    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    # Login via Google as an exemple, you can choose facebook, twitter as you like
    'allauth.socialaccount.providers.google',
)
Run Code Online (Sandbox Code Playgroud)

我还建议设置以下参数来自定义授权过程:

ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = "none"
SOCIALACCOUNT_QUERY_EMAIL = True
LOGIN_REDIRECT_URL = "/"
Run Code Online (Sandbox Code Playgroud)

您可以在此处找到有关可用设置的更多信息。

  • 这些都不能解决问题。 (2认同)