迁移到python 2.7后的TemplateSyntaxError

时间:2013-07-04 00:04:24

标签: python django google-app-engine python-2.7 indexing

我正在从python2.5迁移到python 2.7并且遇到数据库索引问题。主页面已正确生成,但我无法对数据库进行任何操作(添加条目)而不会出现此错误:

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">

我的urls.py包含:

urlpatterns = patterns('', 
    (r'^$', 'views.index'), 
    (r'^new$', 'views.new'), 
    (r'^edit/(\d+)$', 'views.edit'), 
)

使用python 2.5

工作正常

1 个答案:

答案 0 :(得分:1)

在这种情况下,错误是因为item.key.id当前等于空字符串,这与您的网址格式不匹配。

而不是:

(r'^edit/(\d+)$', 'views.edit'), 

尝试:

(r'^edit/(\d*)$', 'views.edit'),