0

我正在从 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

4

1 回答 1

1

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

代替:

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

尝试:

(r'^edit/(\d*)$', 'views.edit'),
于 2013-07-04T00:34:32.240 回答