Python 在URL模式中使用include()时出现意外的NoReverseMatch错误
我在Python 在URL模式中使用include()时出现意外的NoReverseMatch错误,python,regex,django,Python,Regex,Django,我在index.html中引用detail.html时出错 找不到参数为“(3,)”且关键字参数为“{}”的“详细信息”的反转。尝试了1个模式:['$(?P[0-9]+)/$'] 视图.py def rock_and_feat(request): feats = Feat.objects.order_by('-created')[:3] rocks = Rockinfo.objects.order_by('-rank')[:50] context = RequestCon
index.html
中引用detail.html
时出错
找不到参数为“(3,)”且关键字参数为“{}”的“详细信息”的反转。尝试了1个模式:['$(?P[0-9]+)/$']
视图.py
def rock_and_feat(request):
feats = Feat.objects.order_by('-created')[:3]
rocks = Rockinfo.objects.order_by('-rank')[:50]
context = RequestContext(request, {
'feats': feats, 'rocks': rocks
})
return render_to_response('template.html', context)
class DetailView(generic.DetailView):
model = Feat
template_name = 'feature/detail.html'
context_object_name = 'feat'
urlpatterns = [
url(r'^$', views.rock_and_feat, name='rock_and_feat'),
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
]
url.py
def rock_and_feat(request):
feats = Feat.objects.order_by('-created')[:3]
rocks = Rockinfo.objects.order_by('-rank')[:50]
context = RequestContext(request, {
'feats': feats, 'rocks': rocks
})
return render_to_response('template.html', context)
class DetailView(generic.DetailView):
model = Feat
template_name = 'feature/detail.html'
context_object_name = 'feat'
urlpatterns = [
url(r'^$', views.rock_and_feat, name='rock_and_feat'),
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
]
在我添加
之前,应用程序运行良好,这表明存在问题
'$(?P<pk>[0-9]+)/$'
要解决此问题,请从正则表达式中删除美元
url(r'^', include('feature.urls', namespace="feature")),
这说明了问题所在
'$(?P<pk>[0-9]+)/$'
要解决此问题,请从正则表达式中删除美元
url(r'^', include('feature.urls', namespace="feature")),
对不起,我不明白。如上所示,urls.py
中的正则表达式前面没有一美元。你要我做什么改变?我已经编辑了上面的代码,为项目添加了url.py
。当您使用include时,请从正则表达式中删除美元符号,即url(r'^',include('feature.urls',namespace=“feature”),
对不起,我不明白。如上所示,urls.py
中的正则表达式前面没有一美元。你要我做什么改变?我已经编辑了上面的代码,为项目添加了url.py
。使用include时从正则表达式中删除美元符号,即url(r'^',include('feature.url',namespace=“feature”),