这很令人惊讶,我似乎无法摆脱它
下面的代码适用于大多数用户,但当我尝试为userSSENOR呈现链接时,代码会中断,并生成以下错误:
NoReverseMatch at/tofollow/ 找不到参数为“(u'SSenior',)”且关键字参数为“{}”的“profile”的反转。已尝试1个模式:[“用户/(?P\w+/$”]
url.py
url(r'^tofollow/$', views.tofollow, name='tofollow'),
url(r'^user/(?P<username>\w+)/$', views.profile, name='profile'),
template.html
<a href="{% url 'mysite:profile' users.username %}">@{{user.username}}</a>
用户名的末尾有一个空格
正则表达式
\w+
与空格不匹配,因此会出现NoReverseMatch
错误删除空间(您可以使用Django管理员来执行此操作),它将正常工作
相关问题 更多 >
编程相关推荐