/ login /'bool'对象的AttributeError没有属性'rindex' - Django 1.5问题

时间:2013-08-09 05:14:09

标签: python django django-forms django-views django-csrf

每当我尝试登录我正在创建的Django应用程序时,我的浏览器中出现以下错误:

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

这是我的views.py,直到最近才开始工作,现在这个错误正在被抛出。任何人有什么想法到底是怎么回事?

@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,
            })

修改

这是我的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'), 

我的配置文件(settings.py)可以在http://dpaste.com/1336541/

看到

再次编辑 我已经降级回Django 1.5,我仍然遇到这个错误。我不知道发生了什么,为什么我的登录根本不起作用。我真的希望有人可以帮助我解决这个问题,因为我的谷歌搜索没有提出任何对我的情况有用的东西,我真的很沮丧。

1 个答案:

答案 0 :(得分:0)

答案在我的 urls.py

请注意我的views.py如何将正确的登录信息发送到return render_to_response('uc/portal/index.html', {'state':state, 'username':username}, context_instance=RequestContext(request))

原来我的 urls.py 我定义了

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

我没有定义 uc/portal/index.html,因为它在上面。

添加url(r'^portal/$', 'portal.views.portal'),完全解决了我的问题

非常感谢你花时间帮助我! :d