Question

I'm getting the following error in my browser everytime I try to log into my Django app that I'm creating:

Request Method: POST
Request URL:    http://127.0.0.1:8000/login/
Django Version: 1.6 #UPDATE: HAVE DOWNGRADED TO DJANGO 1.5 AND STILL GETTING THIS ERROR
Exception Type: AttributeError
Exception Value:    
'bool' object has no attribute 'rindex'
Exception Location: /Library/Python/2.7/site-packages/django/core/urlresolvers.py in get_mod_func, line 141
Python Executable:  /usr/bin/python
Python Version: 2.7.2
Python Path:    
['/Users/gersande/Public/CompWebsite/uc',
 '/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg',
 '/Library/Python/2.7/site-packages/PyMySQL-0.5-py2.7.egg',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
 '/Library/Python/2.7/site-packages']
Server time:    Fri, 9 Aug 2013 00:09:03 -0500

This is my views.py and it was working until very recently, and now this error is getting thrown around. Anybody have any ideas what on earth is going on?

@csrf_protect
@cache_page(60 * 15)
def login_user(request):
    #inactive_image_url = ""
    #invalid_credentials_url = ""
    context_instance=RequestContext(request)
    if request.POST:
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)            
                state = "You're successfully logged in!"
                return render_to_response('uc/portal/index.html', {'state':state, 'username':username}, context_instance=RequestContext(request))
            else:
                state_img = inactive_image_url
                state = "Your account is not active, please contact UC admin."
        else:
            state_img = invalid_credentials_url
            state = "Your username and/or password were incorrect."
    return render_to_response('uc/index.html', 
            {'state': state,
             'state_img': state_img,
             'username': username
            }, context_instance=RequestContext(request))
def portal(request):
    username = 'username'
    return render_to_response('uc/portal/index.html', 
            {'username': username,
            })

EDIT

This is the my urls.py:

from django.conf.urls import patterns, include, url 
from django.conf import settings 
from django.conf.urls.static import static 
from django.conf.urls import * 

# Uncomment the next two lines to enable the admin: 
from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
url(r'^/$','portal.views.index'), 
url(r'^uc/$', 'portal.views.index'), 
url(r'^$','portal.views.index'), 
url(r'^index/$', 'portal.views.index'), 
# Login / logout. 
url(r'^registration/$', 'portal.views.registration'), 
url(r'^login/$', 'portal.views.login_user'), 
url(r'^portal/$', 'portal.views.portal'), 
# Static part of the website 
url(r'^team/$', 'portal.views.team'), 
url(r'^about/$', 'portal.views.about'), 

My configuration file (settings.py) can be seen at http://dpaste.com/1336541/

EDIT AGAIN I have downgraded back to Django 1.5, and I'm still getting this error. I have no idea what is going on and why my login simply is not working. I'm really hoping somebody can help me figure this one out, because my googling isn't coming up with anything useful to my case and I'm getting really frustrated.

Was it helpful?

Solution

The answer was in my urls.py

Notice how in my views.py I am sending my correct login to return render_to_response('uc/portal/index.html', {'state':state, 'username':username}, context_instance=RequestContext(request))

Turns out that in my urls.py I had defined

 url(r'^portal/$', 'portal.views.portal'), 

but I had not defined uc/portal/index.html as it is above.

adding url(r'^portal/$', 'portal.views.portal'), fixed my problem entirely

Thank you so much to bouke for taking the time to help me out!!! :D

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top