/ rango / newbie的NoReverseMatch在django教程中遇到了探戈

时间:2015-03-03 23:16:59

标签: django

错误消息调试模式:

  

/ rango的NoReverseMatch /对于'category'的反向,带有参数'('other-frameworks',)'和关键字参数'{}'未找到。 1个模式尝试:['rango / category /(?P \ w +)/ $']请求方法:GET请求URL:http://127.0.0.1:8000/rango/ Django版本:1.7.4异常类型:NoReverseMatch异常值:反向找不到带有参数'('other-frameworks',)'和关键字参数'{}'的'category'。尝试了1种模式:['rango / category /(?P \ w +)/ $']异常位置:C:\ Users \ Beheerder \ Desktop \ venv \ lib \ site-packages \ django \ core \ urlresolvers.py在_reverse_with_prefix中,第468行Python可执行文件:C:\ Users \ Beheerder \ Desktop \ venv \ Scripts \ python.exe Python版本:   3.4.2

模板渲染期间出错

  

使用参数'('other-frameworks',''和关键字参数'{}'找不到'category'的反转。尝试过1种模式:['rango / category /(?P \ w +)/ $']

1   {% if cats %}
2       <ul class="nav nav-sidebar">
3       {% for c in cats %}
4           <li><a href="{% url 'category'  c.slug %}">{{ c.name }}</a></li>
5       {% endfor %}
6   
7   {% else %}
8       <li> <strong >There are no category present.</strong></li>
9   
10      </ul>
11  {% endif %}

我(作为新手)不知道这里出了什么问题,

这是指向特定教程部分的链接:http://www.tangowithdjango.com/book17/chapters

from django.conf.urls import patterns, url
from rango import views

    urlpatterns = patterns('',
        url(r'^$', views.index, name='index'),
        url(r'^about/$', views.about, name='about'),
        url(r'^category/(?P<category_name_url>\w+)/$', views.category, name='category'),
        url(r'^add_category/$', views.add_category, name='add_category'),
        url(r'^category/(?P<category_name_slug>\w+)/add_page/$', views.add_page, name='add_page'),
        url(r'^restricted/$', views.restricted, name='restricted'),
        url(r'^add_page/$', views.add_page, name="add_page"),
        )

1 个答案:

答案 0 :(得分:2)

-字符串中的other-frameworks短划线与(字母数字和下划线)\w不匹配。

将网址中的正则表达式更改为[\w-]+

url(r'^category/(?P<category_name_url>[\w-]+)/$', views.category,
                                                  name='category'),