0

每次我尝试登录我正在创建的 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,但我仍然收到此错误。我不知道发生了什么以及为什么我的登录根本不起作用。我真的希望有人能帮我解决这个问题,因为我的谷歌搜索没有找到任何对我的案子有用的东西,我真的很沮丧。

4

1 回答 1

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'),完全解决了我的问题

非常感谢 bouke 抽出时间来帮助我!!!:D

于 2013-08-09T07:14:55.907 回答