2015-11-22 55 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設置採用字符串路徑。

相關問題