呈现时为NoReverseMatch:反向'views.showusersignin',带参数'()'和关键字参数'{'userid':u'rec.0'}'未找到

时间:2012-12-13 11:27:02

标签: python django django-templates

我在stackoverflow上看了很多讨论,但没有一个有用。所以我决定在这里粘贴我的代码。所以请帮助我在哪里做错了。谢谢

这是urls.py

(r'^showusersignin/(?P<userid>\d+)/$', 'views.showusersignin'),

这是views.py中的定义

def showusersignin(request,userid):

这是signin.html

{%for rec in records.object_list%}

        <tr>
            <td width = "15%">
               <a href="{%url views.showusersignin userid='rec.0' %}">{{rec.0}}</a>
            </td>
            <td width = "15%">
                {{rec.1}}
            </td>
            <td width = "15%">
                {{rec.2}}
            </td>

        </tr>
 {%endfor%}

服务器错误

Request Method: GET
Request URL:    mysite/signin
Django Version: 1.2.5
Exception Type: TemplateSyntaxError
Exception Value:    
Caught NoReverseMatch while rendering: Reverse for 'views.showusersignin' with arguments '()' and keyword arguments '{'userid': u'rec.0'}' not found.
Exception Location: /base/python27_runtime/python27_lib/versions/third_party/django-1.2/django/template/defaulttags.py in render, line 385
Python Executable:  /base/python27_runtime/python27_dist/python
Python Version: 2.7.3
Python Path:    ['/base/data/home/apps/s~bgshelloworld/9.363836595528814694', '/base/data/home/apps/s~bgshelloworld/9.363836595528814694', '/base/python27_runtime/python27_dist/lib/python27.zip', '/base/python27_runtime/python27_dist/lib/python2.7', '/base/python27_runtime/python27_dist/lib/python2.7/plat-linux2', '/base/python27_runtime/python27_dist/lib/python2.7/lib-tk', '/base/python27_runtime/python27_dist/lib/python2.7/lib-old', '/base/python27_runtime/python27_dist/lib/python2.7/lib-dynload', '/base/python27_runtime/python27_dist/lib/python2.7/site-packages', '/base/python27_runtime/python27_lib/versions/1', '/base/python27_runtime/python27_lib/versions/third_party/django-1.2', '/base/python27_runtime/python27_lib/versions/third_party/jinja2-2.6', '/base/python27_runtime/python27_lib/versions/third_party/markupsafe-0.15', '/base/python27_runtime/python27_lib/versions/third_party/setuptools-0.6c11', '/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3', '/base/python27_runtime/python27_lib/versions/third_party/webob-1.1.1', '/base/python27_runtime/python27_lib/versions/third_party/yaml-3.10']
Server time:    Thu, 13 Dec 2012 11:11:23 +0000

1 个答案:

答案 0 :(得分:1)

你做错了两件事。

首先,您已将'rec.0'作为字符串放在url标记内。我认为你的意思是传递该列表项的值,所以你应该userid=rec.0

其次,您的URL没有userid参数,因为您没有使用命名参数。将其更改为r'^showusersignin/(?P<user_id>\d+)/$',或将您的网址标记更改为{%url views.showusersignin rec.0 %}