![](/img/trans.png)
[英]Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found
[英]Django NoReverseMatch error Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found
我在這里查看了幾個標題相似的問題,但似乎沒有幫助。 錯誤:
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 %}
主要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教程。 我一直在將我的股票代碼與我的股票代碼進行比較,似乎找不到問題所在。
由於某種原因,您試圖將參數傳遞給索引視圖; 但是那種觀點是不可接受的。 應該只是:
<a href="{% url 'articles:index' %}">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.