启用django-social-auth后端后,django admin无法识别

时间:2016-08-28 20:36:57

标签: python django django-admin

我在我的项目中使用django-social-auth使用facebook登录,但即使从facebook退出后我也无法登录django管理页面。

我以为我忘记了密码并尝试将其从shell中删除:

>>> from django.contrib.auth.models import User
>>> User.objects.filter(is_superuser=True)
<QuerySet []>

这是我的setting.py文件:

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'social.apps.django_app.default',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'portfolio',
    ]

AUTHENTICATION_BACKENDS = (
    # For Facebook Authentication
    'social.backends.facebook.FacebookOAuth2',
    # Default Django Auth Backends
    'django.contrib.auth.backends.ModelBackend',
    )


TEMPLATES = [
    {
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',

             # Setting of Template Context Processors for Social Auth
            'social.apps.django_app.context_processors.backends',
            'social.apps.django_app.context_processors.login_redirect', 
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

models.py:

from django.db import models

class Personal(models.Model):
    name = models.CharField(max_length=100)
    address = models.CharField(max_length=100)
    email = models.EmailField()
    phone = models.CharField(max_length=100)
    status = models.CharField(max_length=100)
    cover = models.CharField(max_length=100)

我有一个form.py文件:

from django import forms
from django.forms import ModelForm
from . import models as m

class PersoForm(ModelForm):
    class Meta:
        model = m.Personal
        fields = ['name', 'status', 'address', 'email', 'phone', 'cover']

我知道我可以创建一个新的超级用户,但我想了解为什么会这样,我怎么能同时使用django-admin和django-social-auth?

我在此感谢一些澄清,我是django框架的新手。

1 个答案:

答案 0 :(得分:0)

你运行python manage.py createsuperuser了吗?看起来你根本没有超级用户。您是如何登录admin的?