LDAP authentication using django Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!What are the differences between LDAP and Active Directory?Does Django scale?How to debug in Django, the good way?How to check Django versiondifferentiate null=True, blank=True in djangoWhat are CN, OU, DC in an LDAP search?Cannot display HTML stringDjango 1.8.3 urls'zinnia_loop_template' received too many positional argumentsAttributeError: 'NoneType' object has no attribute 'split' Getting Error unknowingly on CMD. How to resolve it?

Sum letters are not two different

What initially awakened the Balrog?

As a beginner, should I get a Squier Strat with a SSS config or a HSS?

How to install press fit bottom bracket into new frame

How would a mousetrap for use in space work?

An adverb for when you're not exaggerating

How to write this math term? with cases it isn't working

Crossing US/Canada Border for less than 24 hours

What are the out-of-universe reasons for the references to Toby Maguire-era Spider-Man in Into the Spider-Verse?

Morning, Afternoon, Night Kanji

How to tell that you are a giant?

Can anything be seen from the center of the Boötes void? How dark would it be?

Why is Nikon 1.4g better when Nikon 1.8g is sharper?

Is there hard evidence that the grant peer review system performs significantly better than random?

Question about debouncing - delay of state change

Why is it faster to reheat something than it is to cook it?

How come Sam didn't become Lord of Horn Hill?

Why should I vote and accept answers?

Did Deadpool rescue all of the X-Force?

What is the topology associated with the algebras for the ultrafilter monad?

Drawing without replacement: why is the order of draw irrelevant?

How often does castling occur in grandmaster games?

Is there a kind of relay only consumes power when switching?

How fail-safe is nr as stop bytes?



LDAP authentication using django



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!What are the differences between LDAP and Active Directory?Does Django scale?How to debug in Django, the good way?How to check Django versiondifferentiate null=True, blank=True in djangoWhat are CN, OU, DC in an LDAP search?Cannot display HTML stringDjango 1.8.3 urls'zinnia_loop_template' received too many positional argumentsAttributeError: 'NoneType' object has no attribute 'split' Getting Error unknowingly on CMD. How to resolve it?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Could anyone of you please help me to implement LDAP authentication using Django. I want to develop a web application which should allow users to access the application post LDAP authentication. I have coded the basic things but I get some failures.



Settings.py



"""
Django settings for HandBook project.

Generated by 'django-admin startproject' using Django 2.1.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import os
import ldap
from django_auth_ldap.config import LDAPSearch
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
AUTH_LDAP_SERVER_URI = "serverIp"
AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend')
AUTH_LDAP_CONNECTION_OPTIONS =
ldap.OPT_REFERRALS: 0

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '4xkkb*m!&@^xzhkpe6#gxe@xeee0ug3q0h$@-)#lv8+0dqpid*'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["192.168.113.75"]


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'NewHandBook.apps.NewhandbookConfig',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
]

ROOT_URLCONF = 'HandBook.urls'

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',
],
,
,
]

WSGI_APPLICATION = 'HandBook.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES =
'default':
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),




# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [

'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
,

'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
,

'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
,

'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
,
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'


Views.py



from django.shortcuts import render
from django.contrib.auth import authenticate, login
from django.template import RequestContext
from django.shortcuts import render_to_response


def login(request):
return render(request, 'login/login.html')


def login_user(request):
username = password = ""
state = ""

if request.POST:
username = request.POST.get('username')
password = request.POST.get('password')

print(username, password)

user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return render(request, 'login/base.html', 'state': state, 'username': username)
else:
return render(request, 'login/login.html', 'state': state, 'username': username)
)


login.html



 % extends 'login/base.html' %
% load static %

<html>
<head>
<title>Login</title>
</head>
<body>
% block body %
<form method="post" action="/NewHandBook/validate/">% csrf_token %
<div class="container">
<div class="row">
<div class="col-md-10 offset=md-1">
<div class="row">
<div class="col-md-5 register-left "><br><br>
<img style="width: 350px;position: absolute;margin-left: -350px;margin-top: -80px"
src="% static 'images/gar.png' %">
<h1 style="font-family: Brush Script MT;font-size: 70px;margin-top: 45px;margin-left: -342px">
HandBook.</h1>
<p style="font-family: Courier New;margin-top: -20px;margin-left: -359px "><i
class="fas fa-shield-alt"></i> Secure <i
class="far fa-share-square"></i> Share <i class="far fa-smile-beam"></i> Smile
</p>

</div>

<div class="col-md-7 register-right">
<h2 style="font-family: Courier;color: azure">Login Here</h2>
<h7 style="font-family: Courier;font-size: 13px;color: aliceblue">
<h7 style="color: red">*</h7>
Please use your system credentials
</h7>
<div class="register-form">
<div class="form-group">
<input type="text" name="username" class="form-control" placeholder="User name"
style="font-family: Courier">

</div>
<div class="form-group">
<input type="password" name="password" class="form-control" placeholder="Password"
style="font-family: Courier">

</div>
<input type="reset" class="btn btn-primary" value="Reset">
<button type="submit" class="btn btn-primary"> Login Now</button>

</div>

</div>
</div>
</div>
</div>
</div>
</form>
% endblock %
</body>enter code here
</html>## Heading ##


I get below error when i run my project
exception



Could anyone of you please help me here.



My use case:
user should be able to land on some home page after a successful login or should land back on same login page if provided credentials are invalid.










share|improve this question
























  • Did you run python manage.py makemigrations and python manage.py migrate?

    – Jonhy Beebop
    Mar 22 at 10:11











  • Thanks Jonhy for your response. Yes !! I had run those above commands. Still, I'm getting ImportError at /NewHandBook/validate/ d doesn't look like a module path...... It will be very helpful if you can help me on this.

    – vivek.p.n manu
    Mar 22 at 10:26












  • is /NewHandBook/validate/ validate python package? Or it's just a regular folder? or is it a python file?

    – Jonhy Beebop
    Mar 22 at 10:32












  • In my urls.py, I have just added an redirection to call the function. from django.conf.urls import url from . import views urlpatterns = [ url('login', views.login), url('validate',views.login_user) ]

    – vivek.p.n manu
    Mar 22 at 10:36

















0















Could anyone of you please help me to implement LDAP authentication using Django. I want to develop a web application which should allow users to access the application post LDAP authentication. I have coded the basic things but I get some failures.



Settings.py



"""
Django settings for HandBook project.

Generated by 'django-admin startproject' using Django 2.1.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import os
import ldap
from django_auth_ldap.config import LDAPSearch
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
AUTH_LDAP_SERVER_URI = "serverIp"
AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend')
AUTH_LDAP_CONNECTION_OPTIONS =
ldap.OPT_REFERRALS: 0

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '4xkkb*m!&@^xzhkpe6#gxe@xeee0ug3q0h$@-)#lv8+0dqpid*'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["192.168.113.75"]


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'NewHandBook.apps.NewhandbookConfig',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
]

ROOT_URLCONF = 'HandBook.urls'

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',
],
,
,
]

WSGI_APPLICATION = 'HandBook.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES =
'default':
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),




# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [

'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
,

'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
,

'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
,

'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
,
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'


Views.py



from django.shortcuts import render
from django.contrib.auth import authenticate, login
from django.template import RequestContext
from django.shortcuts import render_to_response


def login(request):
return render(request, 'login/login.html')


def login_user(request):
username = password = ""
state = ""

if request.POST:
username = request.POST.get('username')
password = request.POST.get('password')

print(username, password)

user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return render(request, 'login/base.html', 'state': state, 'username': username)
else:
return render(request, 'login/login.html', 'state': state, 'username': username)
)


login.html



 % extends 'login/base.html' %
% load static %

<html>
<head>
<title>Login</title>
</head>
<body>
% block body %
<form method="post" action="/NewHandBook/validate/">% csrf_token %
<div class="container">
<div class="row">
<div class="col-md-10 offset=md-1">
<div class="row">
<div class="col-md-5 register-left "><br><br>
<img style="width: 350px;position: absolute;margin-left: -350px;margin-top: -80px"
src="% static 'images/gar.png' %">
<h1 style="font-family: Brush Script MT;font-size: 70px;margin-top: 45px;margin-left: -342px">
HandBook.</h1>
<p style="font-family: Courier New;margin-top: -20px;margin-left: -359px "><i
class="fas fa-shield-alt"></i> Secure <i
class="far fa-share-square"></i> Share <i class="far fa-smile-beam"></i> Smile
</p>

</div>

<div class="col-md-7 register-right">
<h2 style="font-family: Courier;color: azure">Login Here</h2>
<h7 style="font-family: Courier;font-size: 13px;color: aliceblue">
<h7 style="color: red">*</h7>
Please use your system credentials
</h7>
<div class="register-form">
<div class="form-group">
<input type="text" name="username" class="form-control" placeholder="User name"
style="font-family: Courier">

</div>
<div class="form-group">
<input type="password" name="password" class="form-control" placeholder="Password"
style="font-family: Courier">

</div>
<input type="reset" class="btn btn-primary" value="Reset">
<button type="submit" class="btn btn-primary"> Login Now</button>

</div>

</div>
</div>
</div>
</div>
</div>
</form>
% endblock %
</body>enter code here
</html>## Heading ##


I get below error when i run my project
exception



Could anyone of you please help me here.



My use case:
user should be able to land on some home page after a successful login or should land back on same login page if provided credentials are invalid.










share|improve this question
























  • Did you run python manage.py makemigrations and python manage.py migrate?

    – Jonhy Beebop
    Mar 22 at 10:11











  • Thanks Jonhy for your response. Yes !! I had run those above commands. Still, I'm getting ImportError at /NewHandBook/validate/ d doesn't look like a module path...... It will be very helpful if you can help me on this.

    – vivek.p.n manu
    Mar 22 at 10:26












  • is /NewHandBook/validate/ validate python package? Or it's just a regular folder? or is it a python file?

    – Jonhy Beebop
    Mar 22 at 10:32












  • In my urls.py, I have just added an redirection to call the function. from django.conf.urls import url from . import views urlpatterns = [ url('login', views.login), url('validate',views.login_user) ]

    – vivek.p.n manu
    Mar 22 at 10:36













0












0








0








Could anyone of you please help me to implement LDAP authentication using Django. I want to develop a web application which should allow users to access the application post LDAP authentication. I have coded the basic things but I get some failures.



Settings.py



"""
Django settings for HandBook project.

Generated by 'django-admin startproject' using Django 2.1.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import os
import ldap
from django_auth_ldap.config import LDAPSearch
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
AUTH_LDAP_SERVER_URI = "serverIp"
AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend')
AUTH_LDAP_CONNECTION_OPTIONS =
ldap.OPT_REFERRALS: 0

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '4xkkb*m!&@^xzhkpe6#gxe@xeee0ug3q0h$@-)#lv8+0dqpid*'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["192.168.113.75"]


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'NewHandBook.apps.NewhandbookConfig',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
]

ROOT_URLCONF = 'HandBook.urls'

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',
],
,
,
]

WSGI_APPLICATION = 'HandBook.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES =
'default':
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),




# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [

'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
,

'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
,

'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
,

'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
,
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'


Views.py



from django.shortcuts import render
from django.contrib.auth import authenticate, login
from django.template import RequestContext
from django.shortcuts import render_to_response


def login(request):
return render(request, 'login/login.html')


def login_user(request):
username = password = ""
state = ""

if request.POST:
username = request.POST.get('username')
password = request.POST.get('password')

print(username, password)

user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return render(request, 'login/base.html', 'state': state, 'username': username)
else:
return render(request, 'login/login.html', 'state': state, 'username': username)
)


login.html



 % extends 'login/base.html' %
% load static %

<html>
<head>
<title>Login</title>
</head>
<body>
% block body %
<form method="post" action="/NewHandBook/validate/">% csrf_token %
<div class="container">
<div class="row">
<div class="col-md-10 offset=md-1">
<div class="row">
<div class="col-md-5 register-left "><br><br>
<img style="width: 350px;position: absolute;margin-left: -350px;margin-top: -80px"
src="% static 'images/gar.png' %">
<h1 style="font-family: Brush Script MT;font-size: 70px;margin-top: 45px;margin-left: -342px">
HandBook.</h1>
<p style="font-family: Courier New;margin-top: -20px;margin-left: -359px "><i
class="fas fa-shield-alt"></i> Secure <i
class="far fa-share-square"></i> Share <i class="far fa-smile-beam"></i> Smile
</p>

</div>

<div class="col-md-7 register-right">
<h2 style="font-family: Courier;color: azure">Login Here</h2>
<h7 style="font-family: Courier;font-size: 13px;color: aliceblue">
<h7 style="color: red">*</h7>
Please use your system credentials
</h7>
<div class="register-form">
<div class="form-group">
<input type="text" name="username" class="form-control" placeholder="User name"
style="font-family: Courier">

</div>
<div class="form-group">
<input type="password" name="password" class="form-control" placeholder="Password"
style="font-family: Courier">

</div>
<input type="reset" class="btn btn-primary" value="Reset">
<button type="submit" class="btn btn-primary"> Login Now</button>

</div>

</div>
</div>
</div>
</div>
</div>
</form>
% endblock %
</body>enter code here
</html>## Heading ##


I get below error when i run my project
exception



Could anyone of you please help me here.



My use case:
user should be able to land on some home page after a successful login or should land back on same login page if provided credentials are invalid.










share|improve this question
















Could anyone of you please help me to implement LDAP authentication using Django. I want to develop a web application which should allow users to access the application post LDAP authentication. I have coded the basic things but I get some failures.



Settings.py



"""
Django settings for HandBook project.

Generated by 'django-admin startproject' using Django 2.1.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import os
import ldap
from django_auth_ldap.config import LDAPSearch
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
AUTH_LDAP_SERVER_URI = "serverIp"
AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend')
AUTH_LDAP_CONNECTION_OPTIONS =
ldap.OPT_REFERRALS: 0

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '4xkkb*m!&@^xzhkpe6#gxe@xeee0ug3q0h$@-)#lv8+0dqpid*'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["192.168.113.75"]


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'NewHandBook.apps.NewhandbookConfig',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
]

ROOT_URLCONF = 'HandBook.urls'

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',
],
,
,
]

WSGI_APPLICATION = 'HandBook.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES =
'default':
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),




# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [

'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
,

'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
,

'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
,

'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
,
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'


Views.py



from django.shortcuts import render
from django.contrib.auth import authenticate, login
from django.template import RequestContext
from django.shortcuts import render_to_response


def login(request):
return render(request, 'login/login.html')


def login_user(request):
username = password = ""
state = ""

if request.POST:
username = request.POST.get('username')
password = request.POST.get('password')

print(username, password)

user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return render(request, 'login/base.html', 'state': state, 'username': username)
else:
return render(request, 'login/login.html', 'state': state, 'username': username)
)


login.html



 % extends 'login/base.html' %
% load static %

<html>
<head>
<title>Login</title>
</head>
<body>
% block body %
<form method="post" action="/NewHandBook/validate/">% csrf_token %
<div class="container">
<div class="row">
<div class="col-md-10 offset=md-1">
<div class="row">
<div class="col-md-5 register-left "><br><br>
<img style="width: 350px;position: absolute;margin-left: -350px;margin-top: -80px"
src="% static 'images/gar.png' %">
<h1 style="font-family: Brush Script MT;font-size: 70px;margin-top: 45px;margin-left: -342px">
HandBook.</h1>
<p style="font-family: Courier New;margin-top: -20px;margin-left: -359px "><i
class="fas fa-shield-alt"></i> Secure <i
class="far fa-share-square"></i> Share <i class="far fa-smile-beam"></i> Smile
</p>

</div>

<div class="col-md-7 register-right">
<h2 style="font-family: Courier;color: azure">Login Here</h2>
<h7 style="font-family: Courier;font-size: 13px;color: aliceblue">
<h7 style="color: red">*</h7>
Please use your system credentials
</h7>
<div class="register-form">
<div class="form-group">
<input type="text" name="username" class="form-control" placeholder="User name"
style="font-family: Courier">

</div>
<div class="form-group">
<input type="password" name="password" class="form-control" placeholder="Password"
style="font-family: Courier">

</div>
<input type="reset" class="btn btn-primary" value="Reset">
<button type="submit" class="btn btn-primary"> Login Now</button>

</div>

</div>
</div>
</div>
</div>
</div>
</form>
% endblock %
</body>enter code here
</html>## Heading ##


I get below error when i run my project
exception



Could anyone of you please help me here.



My use case:
user should be able to land on some home page after a successful login or should land back on same login page if provided credentials are invalid.







python django ldap python-ldap ldapauth






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 15:15







vivek.p.n manu

















asked Mar 22 at 10:09









vivek.p.n manuvivek.p.n manu

35




35












  • Did you run python manage.py makemigrations and python manage.py migrate?

    – Jonhy Beebop
    Mar 22 at 10:11











  • Thanks Jonhy for your response. Yes !! I had run those above commands. Still, I'm getting ImportError at /NewHandBook/validate/ d doesn't look like a module path...... It will be very helpful if you can help me on this.

    – vivek.p.n manu
    Mar 22 at 10:26












  • is /NewHandBook/validate/ validate python package? Or it's just a regular folder? or is it a python file?

    – Jonhy Beebop
    Mar 22 at 10:32












  • In my urls.py, I have just added an redirection to call the function. from django.conf.urls import url from . import views urlpatterns = [ url('login', views.login), url('validate',views.login_user) ]

    – vivek.p.n manu
    Mar 22 at 10:36

















  • Did you run python manage.py makemigrations and python manage.py migrate?

    – Jonhy Beebop
    Mar 22 at 10:11











  • Thanks Jonhy for your response. Yes !! I had run those above commands. Still, I'm getting ImportError at /NewHandBook/validate/ d doesn't look like a module path...... It will be very helpful if you can help me on this.

    – vivek.p.n manu
    Mar 22 at 10:26












  • is /NewHandBook/validate/ validate python package? Or it's just a regular folder? or is it a python file?

    – Jonhy Beebop
    Mar 22 at 10:32












  • In my urls.py, I have just added an redirection to call the function. from django.conf.urls import url from . import views urlpatterns = [ url('login', views.login), url('validate',views.login_user) ]

    – vivek.p.n manu
    Mar 22 at 10:36
















Did you run python manage.py makemigrations and python manage.py migrate?

– Jonhy Beebop
Mar 22 at 10:11





Did you run python manage.py makemigrations and python manage.py migrate?

– Jonhy Beebop
Mar 22 at 10:11













Thanks Jonhy for your response. Yes !! I had run those above commands. Still, I'm getting ImportError at /NewHandBook/validate/ d doesn't look like a module path...... It will be very helpful if you can help me on this.

– vivek.p.n manu
Mar 22 at 10:26






Thanks Jonhy for your response. Yes !! I had run those above commands. Still, I'm getting ImportError at /NewHandBook/validate/ d doesn't look like a module path...... It will be very helpful if you can help me on this.

– vivek.p.n manu
Mar 22 at 10:26














is /NewHandBook/validate/ validate python package? Or it's just a regular folder? or is it a python file?

– Jonhy Beebop
Mar 22 at 10:32






is /NewHandBook/validate/ validate python package? Or it's just a regular folder? or is it a python file?

– Jonhy Beebop
Mar 22 at 10:32














In my urls.py, I have just added an redirection to call the function. from django.conf.urls import url from . import views urlpatterns = [ url('login', views.login), url('validate',views.login_user) ]

– vivek.p.n manu
Mar 22 at 10:36





In my urls.py, I have just added an redirection to call the function. from django.conf.urls import url from . import views urlpatterns = [ url('login', views.login), url('validate',views.login_user) ]

– vivek.p.n manu
Mar 22 at 10:36












1 Answer
1






active

oldest

votes


















0














The error indicates that you are passing a single Python path where you should actually pass a list of Python paths, i.e. django.some.module.path instead of ['django.some.module.path']



Django then iterates over the string, and tries to import each character. In case of django.some.module.path, Django tries to import d, which gives you the error you are seeing.



To pinpoint the exact source of the error, you have to provide the complete traceback. You can click on 'Switch to copy-and-paste view' on the Debug Error page.



Update:



Here is your error:



AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend')


Single entry tuples need a comma, like this:



AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend',)





share|improve this answer

























  • Thanks for your response Daniel !!! Could you please tell me where i should be making the above changes.

    – vivek.p.n manu
    Mar 22 at 11:00











  • stack trace: dpaste.com/3NEMP76#

    – vivek.p.n manu
    Mar 22 at 11:02











  • The stacktrace you posted indicates that error is in the setting AUTHENTICATION_BACKENDS, but it is not listed in your settings.py. Is the settings.py you posted actually the one you are using? It doesn't contain any LDAP specific settings.

    – Daniel Hepper
    Mar 22 at 11:06











  • Sorry...updated the settings.py

    – vivek.p.n manu
    Mar 22 at 11:11











  • Thanks Daniel that works....i have got some ImproperlyConfigured at /NewHandBook/validate/ AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance. Stack trace: dpaste.com/01TBQGR

    – vivek.p.n manu
    Mar 22 at 11:24











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55297269%2fldap-authentication-using-django%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The error indicates that you are passing a single Python path where you should actually pass a list of Python paths, i.e. django.some.module.path instead of ['django.some.module.path']



Django then iterates over the string, and tries to import each character. In case of django.some.module.path, Django tries to import d, which gives you the error you are seeing.



To pinpoint the exact source of the error, you have to provide the complete traceback. You can click on 'Switch to copy-and-paste view' on the Debug Error page.



Update:



Here is your error:



AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend')


Single entry tuples need a comma, like this:



AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend',)





share|improve this answer

























  • Thanks for your response Daniel !!! Could you please tell me where i should be making the above changes.

    – vivek.p.n manu
    Mar 22 at 11:00











  • stack trace: dpaste.com/3NEMP76#

    – vivek.p.n manu
    Mar 22 at 11:02











  • The stacktrace you posted indicates that error is in the setting AUTHENTICATION_BACKENDS, but it is not listed in your settings.py. Is the settings.py you posted actually the one you are using? It doesn't contain any LDAP specific settings.

    – Daniel Hepper
    Mar 22 at 11:06











  • Sorry...updated the settings.py

    – vivek.p.n manu
    Mar 22 at 11:11











  • Thanks Daniel that works....i have got some ImproperlyConfigured at /NewHandBook/validate/ AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance. Stack trace: dpaste.com/01TBQGR

    – vivek.p.n manu
    Mar 22 at 11:24















0














The error indicates that you are passing a single Python path where you should actually pass a list of Python paths, i.e. django.some.module.path instead of ['django.some.module.path']



Django then iterates over the string, and tries to import each character. In case of django.some.module.path, Django tries to import d, which gives you the error you are seeing.



To pinpoint the exact source of the error, you have to provide the complete traceback. You can click on 'Switch to copy-and-paste view' on the Debug Error page.



Update:



Here is your error:



AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend')


Single entry tuples need a comma, like this:



AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend',)





share|improve this answer

























  • Thanks for your response Daniel !!! Could you please tell me where i should be making the above changes.

    – vivek.p.n manu
    Mar 22 at 11:00











  • stack trace: dpaste.com/3NEMP76#

    – vivek.p.n manu
    Mar 22 at 11:02











  • The stacktrace you posted indicates that error is in the setting AUTHENTICATION_BACKENDS, but it is not listed in your settings.py. Is the settings.py you posted actually the one you are using? It doesn't contain any LDAP specific settings.

    – Daniel Hepper
    Mar 22 at 11:06











  • Sorry...updated the settings.py

    – vivek.p.n manu
    Mar 22 at 11:11











  • Thanks Daniel that works....i have got some ImproperlyConfigured at /NewHandBook/validate/ AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance. Stack trace: dpaste.com/01TBQGR

    – vivek.p.n manu
    Mar 22 at 11:24













0












0








0







The error indicates that you are passing a single Python path where you should actually pass a list of Python paths, i.e. django.some.module.path instead of ['django.some.module.path']



Django then iterates over the string, and tries to import each character. In case of django.some.module.path, Django tries to import d, which gives you the error you are seeing.



To pinpoint the exact source of the error, you have to provide the complete traceback. You can click on 'Switch to copy-and-paste view' on the Debug Error page.



Update:



Here is your error:



AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend')


Single entry tuples need a comma, like this:



AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend',)





share|improve this answer















The error indicates that you are passing a single Python path where you should actually pass a list of Python paths, i.e. django.some.module.path instead of ['django.some.module.path']



Django then iterates over the string, and tries to import each character. In case of django.some.module.path, Django tries to import d, which gives you the error you are seeing.



To pinpoint the exact source of the error, you have to provide the complete traceback. You can click on 'Switch to copy-and-paste view' on the Debug Error page.



Update:



Here is your error:



AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend')


Single entry tuples need a comma, like this:



AUTHENTICATION_BACKENDS = ('django_auth_ldap.backend.LDAPBackend',)






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 22 at 11:13

























answered Mar 22 at 10:55









Daniel HepperDaniel Hepper

18.1k54861




18.1k54861












  • Thanks for your response Daniel !!! Could you please tell me where i should be making the above changes.

    – vivek.p.n manu
    Mar 22 at 11:00











  • stack trace: dpaste.com/3NEMP76#

    – vivek.p.n manu
    Mar 22 at 11:02











  • The stacktrace you posted indicates that error is in the setting AUTHENTICATION_BACKENDS, but it is not listed in your settings.py. Is the settings.py you posted actually the one you are using? It doesn't contain any LDAP specific settings.

    – Daniel Hepper
    Mar 22 at 11:06











  • Sorry...updated the settings.py

    – vivek.p.n manu
    Mar 22 at 11:11











  • Thanks Daniel that works....i have got some ImproperlyConfigured at /NewHandBook/validate/ AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance. Stack trace: dpaste.com/01TBQGR

    – vivek.p.n manu
    Mar 22 at 11:24

















  • Thanks for your response Daniel !!! Could you please tell me where i should be making the above changes.

    – vivek.p.n manu
    Mar 22 at 11:00











  • stack trace: dpaste.com/3NEMP76#

    – vivek.p.n manu
    Mar 22 at 11:02











  • The stacktrace you posted indicates that error is in the setting AUTHENTICATION_BACKENDS, but it is not listed in your settings.py. Is the settings.py you posted actually the one you are using? It doesn't contain any LDAP specific settings.

    – Daniel Hepper
    Mar 22 at 11:06











  • Sorry...updated the settings.py

    – vivek.p.n manu
    Mar 22 at 11:11











  • Thanks Daniel that works....i have got some ImproperlyConfigured at /NewHandBook/validate/ AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance. Stack trace: dpaste.com/01TBQGR

    – vivek.p.n manu
    Mar 22 at 11:24
















Thanks for your response Daniel !!! Could you please tell me where i should be making the above changes.

– vivek.p.n manu
Mar 22 at 11:00





Thanks for your response Daniel !!! Could you please tell me where i should be making the above changes.

– vivek.p.n manu
Mar 22 at 11:00













stack trace: dpaste.com/3NEMP76#

– vivek.p.n manu
Mar 22 at 11:02





stack trace: dpaste.com/3NEMP76#

– vivek.p.n manu
Mar 22 at 11:02













The stacktrace you posted indicates that error is in the setting AUTHENTICATION_BACKENDS, but it is not listed in your settings.py. Is the settings.py you posted actually the one you are using? It doesn't contain any LDAP specific settings.

– Daniel Hepper
Mar 22 at 11:06





The stacktrace you posted indicates that error is in the setting AUTHENTICATION_BACKENDS, but it is not listed in your settings.py. Is the settings.py you posted actually the one you are using? It doesn't contain any LDAP specific settings.

– Daniel Hepper
Mar 22 at 11:06













Sorry...updated the settings.py

– vivek.p.n manu
Mar 22 at 11:11





Sorry...updated the settings.py

– vivek.p.n manu
Mar 22 at 11:11













Thanks Daniel that works....i have got some ImproperlyConfigured at /NewHandBook/validate/ AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance. Stack trace: dpaste.com/01TBQGR

– vivek.p.n manu
Mar 22 at 11:24





Thanks Daniel that works....i have got some ImproperlyConfigured at /NewHandBook/validate/ AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance. Stack trace: dpaste.com/01TBQGR

– vivek.p.n manu
Mar 22 at 11:24



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55297269%2fldap-authentication-using-django%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript