0
from django.views import generic
from .models import Inspectionfile
from .models import  posts

class IndexView(generic.ListView):
    template_name = "posts/index.html"

def get_queryset(self):
    return Inspectionfile.objects.all()

class DetailView(generic.DetailView):
    model = Inspectionfile
    template_name = "posts/detail.html "

#index template
<ul>
  {% for o in object_list %}
    <li><a href = "/posts/{{o.id}}/">{{o.document_title}} </a> </li>
  {% endfor %}
</ul>


#detail template
 <h1>{{ o.document_title }}</h1>

My Index template works but the detail template does not seem to take the value so just appears blank . So is the 'o' not being passed to detail ?? I have not been able to solve this. BTW document_title is one of the field of my inspectionfile model. I checked my url regex and it seems to work fine.

1 Answers1

0

o is an object which only exists within the for loop in your list view template. It isn't passed anywhere.

The detail view has its own context; there the object that is identifued by the url argument is called just object.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • That was my first thought!! But then I saw some people doing it this way , they must have global object or something. Anyways worked like a charm!! Thank you so much!! – Ishan Subedi Nov 13 '16 at 19:00