I've looked at a few similarly-titled questions on here, but none seem to help. Error:
我在这里看了一些题目类似的问题,但似乎没有一个有用。错误:
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
:
文章/ 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
:
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:
主要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)),
)
A lot of this code is taken from the django tutorial. I've been comparing mine against the stock code, and can't seem to find the problem.
这些代码中有很多来自django教程。我一直在比较我的股票代码,似乎找不到问题所在。
1 个解决方案
#1
3
You're trying to pass an argument to the index view, for some reason; but that view doesn't accept one. It should just be:
出于某种原因,你试图将参数传递给索引视图;但这种观点并不接受。应该是:
<a href="{% url 'articles:index' %}">
#1
3
You're trying to pass an argument to the index view, for some reason; but that view doesn't accept one. It should just be:
出于某种原因,你试图将参数传递给索引视图;但这种观点并不接受。应该是:
<a href="{% url 'articles:index' %}">