Django 1.5 NoReverseMatch at / dashboard / projects /

时间:2013-12-18 12:39:42

标签: python django-1.5

当我访问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.

仪表板/ views.py

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

仪表板/ urls.py

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'),
)

MY_PROJECT / urls.py

urlpatterns = patterns('',
    url(r'^dashboard/', include('frontend.urls', namespace='dashboard'),),
    url(r'admin/' ,include(admin.site.urls)),
)

projects.html

{% url 'project-details' project.pk %}

1 个答案:

答案 0 :(得分:1)

您将网址模式定义为使用命名组,因此您需要将命名参数传递给url标记,即{% url 'project-details' pk=project.pk %}

此外,您希望使用插入符启动您的网址格式,以确保它们不匹配超出需要,即:^project/$^project/(?P<pk>\d+)/$