AttributeError: 'str'对象没有'regex'属性
在使用旧版的 django 1.3.1 时,遇到了在模板中使用 URL 名称模式的问题。
urls.py 文件:
urlpatterns = patterns(
'project.views',
url(r'^web/login/', 'login', name="web_login"),
)
在 views 中渲染模板时,像这样:
return render_to_response('index.html', context_instance=RequestContext(request))
在 模板 中使用 URL 命名模式,像这样:
<form id="loginForm" action="{% url web_login %}" method="POST">
在渲染模板时出现了错误
AttributeError: 'str' 对象没有 'regex' 属性
1 个回答
0
你忘记加一些引号了。
action="{% url 'web_login' %}"