2015-11-22 49 views
0

我一直在编写一个小应用程序,我需要通过电子邮件验证用户(作为用户名字段)所以我写了一个自定义的AuthenticationBackend。但是当我导入模块时,出现以下错误。当我尝试导入我的自定义后端时Settings.py抛出错误

django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty 

但我的secret_key字段不是空的。当我删除导入时,我不会收到错误。 这里是我的auth_back.py(其中包含AuthenticationBackend)

from django.contrib.auth.models import User 
from user_manager.models import AllUser 
class CustomBackend(object): 
    def authenticate(self, email=None, password=None): 
     try: 
      o = AllUser.objects.get(email=email, password=password) 
     except AllUser.DoesNotExist: 

       return None 
     return User.objects.get(email=o.email) 
    def get_user(self, user_id): 
     try: 
      return User.objects.get(pk=user_id) 
     except User.DoesNotExist: 
      return None 

这里是我的settings.py导入。我把它放在顶部。

from auth_back import CustomBackend 
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
import os 
AUTHENTICATION_BACKENDS = ('auth_back.MyCustomBackend',) 

我把auth_back.py在我的项目的根文件夹(在我的settings.py和wsgi.py住同一个文件夹) 在此先感谢。

回答

1

没有理由将您的后端导入设置。与所有其他设置一样,AUTHENTICATION_BACKENDS设置采用字符串路径。

相关问题