Hi,
 i have try to login user using the guide from
https://docs.djangoproject.com/en/1.11/topics/auth/default/

but get an error. Can someone advise what i am doin wrong here



he is my view.py

#Authentication user
def login(request):
    username=request.POST['username']
    password=request.POST['password']
    user=authenticate(request,username=username,password=password)
    if user is not None:
        login(request,user)
        #Redirect to dashboard page
        return render(request,'dashboard.html')
    else:
        # return invalid login message
        return HttpResponse( 'You have enter a wrong password or username
please again')



Error message:


Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/login/

Django Version: 1.11
Python Version: 2.7.12
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'fundmanager']
Installed 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']



Traceback:

File
"/root/.virtualenvs/benchmark/local/lib/python2.7/site-packages/django/core/handlers/exception.py"
in inner
  41.             response = get_response(request)

File
"/root/.virtualenvs/benchmark/local/lib/python2.7/site-packages/django/core/handlers/base.py"
in _get_response
  187.                 response = self.process_exception_by_middleware(e,
request)

File
"/root/.virtualenvs/benchmark/local/lib/python2.7/site-packages/django/core/handlers/base.py"
in _get_response
  185.                 response = wrapped_callback(request, *callback_args,
**callback_kwargs)

File "/var/www/projects/benchmark/fundmanager/views.py" in login
  22.     username=request.POST['username']

File
"/root/.virtualenvs/benchmark/local/lib/python2.7/site-packages/django/utils/datastructures.py"
in __getitem__
  85.             raise MultiValueDictKeyError(repr(key))

Exception Type: MultiValueDictKeyError at /login/
Exception Value: "u'username'"

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPCf-y4Lg1ZkqDA4TR7RuV6z-gutuKmzFZ%2BvpQsr%3DUnqXV2OkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to