跟随django教程(1.6 python 3.3)。然而,我一直试图在我自己的测试应用程序中复制教程。
我想在索引页面上显示仅3个超链接的列表。现在的超链接只是列出项目的名称。
Views.py
def Index(request):
tables = []
tables.append('Country')
tables.append('County')
tables.append('Registration Body')
return render(request, 'test_app/index.html', {'table_list': tables})
Urls.py
from django.conf.urls import patterns, url
from test_app import views
urlpatterns = patterns('test_app',
#url(r'^Country/', views.Index, name='index'),
url(r'^$', views.Index, name='index'),
)
的index.html
<h1>List of Config Tables in TestApp</h1>
{% if table_list %}
<ul>
{% for tbl_name in table_list %}
<li><a href="{% url 'test_app:index' tbl_name%}">{{ tbl_name }}</a></li>
{% endfor %}
</ul>
{% else %}
<ul>
<p>No table found<p>
</ul>
{% endif %}
使用该设置,我收到错误:
NoReverseMatch at /test_app/
Reverse for 'index' with arguments '('Country',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['test_app/$']
奇怪的是,当我摆脱索引页面中的href中的tbl_name
时,我能够获得我的列表,但列表没有超链接。