迁移到python 2.7后的TemplateSyntaxError
我正在从python2.5迁移到python2.7,数据库索引有问题。主页已正确生成,但我无法对数据库执行任何操作(添加条目),除非出现以下错误:迁移到python 2.7后的TemplateSyntaxError,python,django,google-app-engine,python-2.7,indexing,Python,Django,Google App Engine,Python 2.7,Indexing,我正在从python2.5迁移到python2.7,数据库索引有问题。主页已正确生成,但我无法对数据库执行任何操作(添加条目),除非出现以下错误: TemplateSyntaxError at /new Caught NoReverseMatch while rendering: Reverse for 'views.edit' with arguments '('',)' and keyword arguments '{}' not found. Request Method: GET
TemplateSyntaxError at /new
Caught NoReverseMatch while rendering: Reverse for 'views.edit' with
arguments '('',)' and keyword arguments '{}' not found.
Request Method: GET
Exception Type: TemplateSyntaxError
Exception Value:
Caught NoReverseMatch while rendering: Reverse for 'views.edit' with
arguments '('',)' and keyword arguments '{}' not found.
Exception Location: /Applications/GoogleAppEngineLauncher.app/Contents/Resources/
GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-
1.2/django/template/defaulttags.py in render, line 385
Template error
In template /.../templates/item.html, error at line 5
Caught NoReverseMatch while rendering: Reverse for 'views.edit' with
arguments '('',)' and keyword arguments '{}' not found.
以下是我在第5行看到的:
<form action="{%url views.edit item.key.id%}" method="post">
它在python 2.5中运行良好。在本例中,错误是因为
item.key.id
当前等于一个空字符串,与您的url模式不匹配
而不是:
(r'^edit/(\d+)$', 'views.edit'),
尝试:
这应该改变吗?urlpatterns=patterns(“”,(r’^$,‘views.index’),(r’^new$,‘views.new’,(r’^edit/(\d+),‘views.edit’,)这确实要视情况而定,但如果将编辑模式中的“+”更改为“*”,则它将匹配。至于这是否能完全解决你的问题,我不确定。
(r'^edit/(\d+)$', 'views.edit'),
(r'^edit/(\d*)$', 'views.edit'),