Python 属性错误位于/login/';布尔';对象没有属性';rindex';-Django 1.5版
每次我尝试登录到我正在创建的Django应用程序时,我的浏览器中都会出现以下错误:Python 属性错误位于/login/';布尔';对象没有属性';rindex';-Django 1.5版,python,django,django-forms,django-views,django-csrf,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: 'b
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,
})
编辑
这是我的url.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)可以在
再次编辑
我已经降级回Django 1.5,我仍然会遇到这个错误。我不知道发生了什么,为什么我的登录根本不起作用。我真的希望有人能帮我解决这个问题,因为我的谷歌搜索对我的案子没有任何帮助,我真的很沮丧 答案在我的url.py中 请注意,在my views.py中,我是如何将正确的登录名发送到
return render\u to\u响应('uc/portal/index.html',{'state':state,'username'},context\u instance=RequestContext(request))
事实证明,在我的url.py中,我定义了
url(r'^portal/$', 'portal.views.portal'),
但是我没有像上面那样定义uc/portal/index.html
添加url(r'^portal/$,'portal.views.portal'),
完全解决了我的问题
非常感谢你抽出时间来帮助我!!!:D是否有名为注册的查看功能?a还没有。这只是从我的实际代码中粘贴的副本-这是一个问题,我还没有这个视图吗?在我看来,您的urlconf中似乎有一个错误。首先:不要注册不存在的视图!第二:使用
url()
方法而不是元组,这使得它更显式,并且更容易调试。因此,最后一行变成:url(r'^portal/$,'portal.views.portal'),
。我注意到您正在使用Django 1.6(目前为alpha版本),除非您有充分的理由,否则您应该使用类似于1.5的稳定版本。