[英]Django 1.8 No Reverse Match At Error
每次我点击template.html
的链接时,我都会收到以下错误消息http://prntscr.com/7f3l4d 。 有人可以帮我解决这个问题。
urls.py
项目
urlpatterns = [
url(r'^', include('feature.urls', namespace="feature")),
url(r'^admin/', include(admin.site.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urls.py
app
urlpatterns = [
url(r'^$', views.rock_and_feat, name='rock_and_feat'),
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
]
views.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'
template.html
{% extends "index.html" %}
{% block mainmast %}
<div id="wrapper">
{% if feats %}
{% for feat in feats %}
<div class="specialsticky">
<a href="{% url 'detail' feat.id %}"><img src="{{ feat.image.url }}" alt="some text"></a>
<h1 class="mast-header">
<a href="#">{{feat.title}}</a>
</h1>
</div>
{% endfor %}
{% else %}
<p>No </p>
{% endif %}
</div>
{% endblock %}
当我点击template.html
的图像时,会发生错误。谢谢。
您已将应用程序的URL放在命名空间feature
,因此在引用该URL时,必须使用命名空间。
url(r'^', include('feature.urls', namespace="feature")),
将您的模板更改为: <a href="{% url 'feature:detail' feat.id %}">
它将起作用。
https://docs.djangoproject.com/en/1.8/topics/http/urls/#url-namespaces
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.