Django 1.8 No reverse match on error

I get the following error http://prntscr.com/7f3l4d every time I click a link in template.html

. Can someone help me with this.

urls.py

project

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

Appendix

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 %}

      

When I click on the image in template.html

, an error occurs. Thank.

+3


source to share


1 answer


You have placed your app url in a namespace feature

, so when referring to that url, you must use a namespace.

url(r'^', include('feature.urls', namespace="feature")),



Change your template to: <a href="{% url 'feature:detail' feat.id %}">

and it will work.

https://docs.djangoproject.com/en/1.8/topics/http/urls/#url-namespaces

+5


source







All Articles