当我访问http://example.com:8000/dashboard/projects/时,我正在使用django 1.5我收到错误NoReverseMatch at /dashboard/projects/ Reverse for 'project-details' with arguments '(1,)' and keyword arguments '{}' not found.
class ProjectlistView(ListView):
"""
Project list page
"""
template_name = 'projects.html'
model = Project
context_object_name = 'projects'
paginate_by = 5
class ProjectDetailsView(DetailView):
"""
Project details page
"""
template_name = 'project-details.html'
model = Project
urlpatterns = patterns('',
url(regex=r'^$', view=DashboardView.as_view(), name='index'),
url(regex=r'projects/$', view=ProjectlistView.as_view(), name='projects'),
url(regex=r'project/(?P<pk>\d+)/$', view=ProjectDetailsView.as_view(), name='project-details'),
)
urlpatterns = patterns('',
url(r'^dashboard/', include('frontend.urls', namespace='dashboard'),),
url(r'admin/' ,include(admin.site.urls)),
)
{% url 'project-details' project.pk %}
答案 0 :(得分:1)
您将网址模式定义为使用命名组,因此您需要将命名参数传递给url
标记,即{% url 'project-details' pk=project.pk %}
。
此外,您希望使用插入符启动您的网址格式,以确保它们不匹配超出需要,即:^project/$
和^project/(?P<pk>\d+)/$
。