Python 将id传递给url链接-Django

Python 将id传递给url链接-Django,python,django,Python,Django,我需要在我的show.html页面中传递一个cluster\u id,以防用户希望停止创建的集群。我的url.py看起来像: from django.conf.urls import url from django.core.context_processors import csrf from django.shortcuts import render_to_response from clusters import views urlpatterns = [ url(r'^$'

我需要在我的
show.html
页面中传递一个
cluster\u id
,以防用户希望停止创建的集群。我的
url.py
看起来像:

from django.conf.urls import url
from django.core.context_processors import csrf
from django.shortcuts import render_to_response

from clusters import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^register/', views.register, name='register'),
    url(r'^show/', views.show, name='show'),
    url(r'^login/', views.user_login, name='login'),
    url(r'^logout/', views.user_logout, name='logout'),
    url(r'^destroy_clusters/', views.destroy_clusters, name='destroy_clusters'),
    url(r'^halt_clusters/(?P<cluster_id>\d+)/$', views.halt_clusters, name='halt_clusters'),
    url(r'^check_log_status/', views.check_log_status, name='check_log_status'),
    url(r'^read_cluster_log/', views.read_cluster_log, name='read_cluster_log'),
]
因此,当我执行网页时,我有:

NoReverseMatch at /clusters/register/
Reverse for '' with arguments '()' and keyword arguments '{u'cluster_id': 19L}' not found. 0 pattern(s) tried: []
这让我快发疯了!!为什么我不能把身份证传过去?我看了这个例子:但它似乎不适合我。帮忙?
我的
Django
版本是
1.8。dev

在最近的Django中,您应该在标记中引用文本URL名称:

{% url "halt_clusters" cluster_id=cluster.id %}
否则Django将在您的上下文中查找
halt\u clusters
变量,并将其值用作URL名称

哦,在进行此操作时,您不必指定关键字参数名称,因此这也应该起作用:

{% url "halt_clusters" cluster.id %}

您使用的是什么django版本?@stable用django版本更新了问题。假设您需要
{% url "halt_clusters" cluster.id %}