繁体   English   中英

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

[英]AttributeError at /login/ 'bool' object has no attribute 'rindex' - Django 1.5 issue

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

答案在我的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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM