我有这个网址参考
{% url 'mahasiswa:mhs_delete' mhs.id %}
{% url 'mahasiswa:mhs_edit' mhs.id %}
在urls.py中使用此模式
from django.conf.urls import patterns, url
from mahasiswa import views
urlpatterns = patterns('',
url(r'^$', views.mhs_list, name='mhs_list'),
url(r'^new$', views.mhs_create, name='mhs_new'),
url(r'^edit/(?P<pk>\d+)$', views.mhs_update, name='mhs_edit'),
url(r'^delete/(?P<pk>\d+)$', views.mhs_delete, name='mhs_delete'),
)
我收到了错误:
反转&#39; mhs_edit&#39;有参数&#39;(无,)&#39;和关键字参数 &#39; {}&#39;未找到。尝试了1种模式:[u&#39; mahasiswa / edit /(?P \ d +)$&#39;]
帮我解决一下......
答案 0 :(得分:1)
您的urlpatterns中只有mhs_edit
的一个网址格式:
url(r'^edit/(?P<pk>\d+)$', views.mhs_update, name='mhs_edit')
但该视图采用1个参数:类型pk
的{{1}}(匹配接受至少一个数字的任何字符串)。参数typle \d+
不适合原型。你可以尝试:
(None,)
或
reverse('mhs_edit', args=(123,))