Django NoReverseMatch错误反向'详细信息'有参数'('',)'和关键字参数' {}'未找到

时间:2014-10-18 17:00:35

标签: python django

我在这里看了一些类似标题的问题,但似乎都没有帮助。错误:

NoReverseMatch at /articles/
Reverse for 'index' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'articles/$']

Error during template rendering

In template C:\Projects\django\the_Bluntist\articles\templates\articles\index.html, **error at line 7**
Reverse for 'index' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'articles/$']


    1   {% load staticfiles %}
    2   
    3   <link rel="stylesheet" type="text/css" href="{% static 'articles/style.css' %}" />
    4   {% if latest_articles_list %}
    5       <ul>
    6       {% for article in latest_articles_list %}
    7           <li><a href="{% url 'articles:index' content.slugline %}">{{ content.title }}</a></li>
    8       {% endfor %}
    9       </ul>
    10  {% else %}
    11      <p>No articles are available.</p>
    12  {% endif %}

articles/urls.py

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

urlpatterns = patterns('',
    url(r'^$', views.IndexView.as_view(), name = 'index'),
    url(r'^(?P<slugline>[-\w\d]+),(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail')
)

index.html

{% load staticfiles %}

<link rel="stylesheet" type="text/css" href="{% static 'articles/style.css' %}" />
{% if latest_articles_list %}
    <ul>
    {% for article in latest_articles_list %}
        <li><a href="{% url 'articles:index' content.slugline %}">{{ content.title }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No articles are available.</p>
{% endif %}

main urls.py:

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

    url(r'^articles/', include('articles.urls', namespace="articles")),
    url(r'^admin/', include(admin.site.urls)),
)

很多代码都来自django教程。我一直在比较我的股票代码,似乎无法找到问题。

1 个答案:

答案 0 :(得分:3)

由于某种原因,您试图将参数传递给索引视图;但这种观点并不接受。它应该只是:

<a href="{% url 'articles:index' %}">