Settings.py throws error when I try to import my custom backend

sajid

I have been writing a small app for which I need to authenticate users via email (as username field) So I have written a custom AuthenticationBackend. But when I import the module, I get the below error.

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

But my secret_key field is not empty. And when I remove the import I don't get the error. Here is my auth_back.py (which contains the 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

Here is the import in my settings.py. I placed this at the top.

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

I placed the auth_back.py at the root folder of my project (same folder where my settings.py and wsgi.py live) Thanks in advance.

Daniel Roseman

There is no reason to import your backend into settings. The AUTHENTICATION_BACKENDS setting, like all the other settings, takes a string path.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I have a view that runs fine when executed, but when I try to open it in design mode, it throws a parsing error

Invalid BACKEND error when I have the seemingly correct settings -- why?

Google Speech Recognition module throws error when I try it out

Import error when I try use "requests" module

When i try to refresh my page i have this error

How do I import constants from my settings.py file into my Django console?

Why do I see `503 Backend Error` when I try to get a Cloud Storage service account?

I got the message: "Bad import syntax:" when I try to import a python function inside my gnuradio flowgraph

Getting error when I import LoginBackEnd module into settings.py

Error when I try to rename fieldname in my models.py

Discord.py I'm getting this error when I try to send a custom prefix to a JSON file: Expecting value: line 1 column 1 (char 0)

React - Firebase module error when i try to import 'firebase/app'

how do i set my authentication backend as default in settings.py file of my django project(Extended AbstractBaseUser model)

My program throws an error when I try to run it on Linux (works fine on windows)

I get error 500 (Internal Server Error) when I try to pay with Payola/Stripe (Custom Form) in my Rails 4.1.8 application

Why my Swift app throws a fatal error when I try to unwrap the optional?

Django installed but throws import error in virtual env when running: sudo python manage.py collectstatic

I keep getting an error when I try to import tkFileDialog

When I try to sync my Gradle files I get an error

How do I fix this error in my Django settings.py?

Gcc throws error when I try to compile the test folder in libburn

error when I try import DropDown react-native

When I try to define settings, I get a different error

Internal server error in flask application when I try to import pandas

I am getting empty array when I try to upload multiple images to my backend

react native custom framework, import is not working as it should when i try to import framework into demo app

When i try to update my json file i get a error

When I try to declare a global variable it throws the error Statement expected

Windows make throws an error when I try to use "if EXIST"