django - DetailView template not displaying model data -


i have model want display detail view, have created list view has link leads detailed view. dont errors template doesn't render of models detail link detailview

<a href="../ancillaries/{{ ancillary.id }}" > product </a> 

model

from django.db import models django.core.urlresolvers import reverse  class ancillary(models.model):      product_code = models.charfield(max_length=60, null=true)      type = models.charfield(max_length=120, null=true)      product = models.charfield(max_length=120, null=true)      standard = models.charfield(max_length=120,   null=true)      measurement = models.charfield(max_length=120,  null=true)      brand = models.charfield(max_length=120,   null=true)       class meta:           verbose_name_plural = "ancillaries"      def get_absolute_url(self):           return reverse('ancillaries')      def __unicode__(self):           return u'%s %s %s %s %s %s  %s' % (self.id, self.product_code, self.type,                                  self.product, self.standard,                                  self.measurement, self.brand) 

view

class ancillarydetail(detailview):     model = ancillary     def get_context_data(self, **kwargs):          context = super(ancillarydetail, self).get_context_data(**kwargs)         context['ancillary_list'] = ancillary.objects.all()        return context 

urls

url(r'^ancillaries/(?p<pk>\d+)/', ancillarydetail.as_view(template_name='ancillary-detail.html')), 

template

{% ancillary_list in object_list %} {{ ancillary.product}} {{ ancillary.type }} {{ ancillary.brand }} {{ ancillary.measurement }} {% endfor %} 

it looks though you've used documentation adapted listview example incorrectly. if want display single model instance detailview correct view.

as @mrkre suggested should name url pattern (although use singular form name).

url(r'^ancillaries/(?p<pk>\d+)/', ancillarydetail.as_view(                 template_name='ancillary-detail.html'), name="ancillary_detail") 

the view simply

class ancillarydetail(detailview):     model = ancillary 

in template ancillary-detail.html access model instance using default name object.

{{ object.product}} {{ object.type }} {{ object.brand }} {{ object.measurement }} 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -