'str' object has no attribute 'regex'
错误标题:'str' object has no attribute 'regex'
错误描述:
AttributeError at /user/register/
'str' object has no attribute 'regex'Request Method: POST
Request URL: http://127.0.0.1:8000/user/register/
Django Version: 1.3.1
Exception Type: AttributeError
Exception Value: 'str' object has no attribute 'regex'
Exception Location: C:\Python25\Lib\site-packages\django\core\urlresolvers.py in _populate, line 198
Python Executable: C:\Python25\python.exe
Python Version: 2.5.4
Python Path: ['F:\\demo\\python\\UCenter\\UCenter',
'C:\\Python25\\lib\\site-packages\\setuptools-0.6c8-py2.5.egg',
'C:\\Program Files (x86)\\JetBrains\\PyCharm 1.5.3\\helpers',
'F:\\demo\\python\\UCenter\\UCenter',
'F:\\demo\\python\\UCenter',
'C:\\Windows\\system32\\python25.zip',
'C:\\Python25\\DLLs',
'C:\\Python25\\lib',
'C:\\Python25\\lib\\plat-win',
'C:\\Python25\\lib\\lib-tk',
'C:\\Python25',
'C:\\Python25\\lib\\site-packages',
'C:\\Python25\\lib\\site-packages\\PIL',
'C:\\Python25\\lib\\site-packages\\win32',
'C:\\Python25\\lib\\site-packages\\win32\\lib',
'C:\\Python25\\lib\\site-packages\\Pythonwin']
Server time: Thu, 3 Nov 2011 10:07:47 +0800
错误分析:
vews.py 中的返回页面:return HttpResponseRedirect(reverse('user_index'))
urls.py 中的配置如:
from django.conf.urls.defaults import patterns, url
import os
import settings
#from django.views.generic import ListView,DetailView
#from users.models import UserInfo
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
url(r'^user/register/$','UCenter.users.views.register',name='user_register'),
#url(r'^index/$','UCenter.users.views.index',name='user_index'),
url(r'^index/$','UCenter.users.views.index',name='user_index'),
# Examples:
)
错误因为是user_index 不能映射到URL地址http://127.0.0.1:8000/index/
也就是URL映射有问题。
解决方案:
方案一:直接修改return HttpResponseRedirect('/index/')