2

I'm working on a Django project and the following error showed up

TypeError at /log_in/
'method' object is not subscriptable
Request Method: POST
Request URL:    http://127.0.0.1:8000/log_in/
Django Version: 1.8.4
Exception Type: TypeError
Exception Value:    
'method' object is not subscriptable
Exception Location: D:\pfd\recom\views.py in log_in, line 95
Python Executable:  C:\Python34\python.exe
Python Version: 3.4.3
Python Path:    
['D:\\pfd',
 'C:\\Python34\\lib\\site-packages\\virtualenv-13.1.2-py3.4.egg',
 'C:\\Windows\\SYSTEM32\\python34.zip',
 'C:\\Python34\\DLLs',
 'C:\\Python34\\lib',
 'C:\\Python34',
 'C:\\Python34\\lib\\site-packages']
Server time:    Thu, 1 Oct 2015 22:34:00 +0530

and below is my log_in def

def log_in(request):
    context = RequestContext(request)
    if request.method == 'POST':
        username = request.POST.get['username','']
        password = request.POST.get['password','']
        user = auth.authenticate(username=username, password=password)

    if user is not None:
        if user.is_active:
            auth.login(request,user)
            return HttpResponseRedirect('/loggedin/')
        else:
            return HttpResponse("Inactive user.")
    else:
        return HttpResponseRedirect('error.html')

return render_to_response('error.html')

Can't understand what's wrong.

Changed request.method to request.POST. When deleting context the post is not getting detected, only last statement gets executed.

When trying to delete request.method the same error shows up. Please help...

1
  • What's on line 95? Commented Oct 1, 2015 at 17:17

1 Answer 1

2

Your issue is in these lines of code:

    username = request.POST.get['username','']
    password = request.POST.get['password','']

Should be

    username = request.POST.get('username','')
    password = request.POST.get('password','')

Or, even

    username = request.POST['username']
    password = request.POST['password']

Note that using the second syntax would raise exception if the key is not present.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.