Friday, February 26, 2016

errors while trying to add extra context (detailview, __getitem__)

File "/home/malikarumi/Projects/cannon/jamf/essell/urls.py", line 23, in <module>
    url(r'^code/(?P<slug>)/', CodeDetailView.as_view(), name='family'),
TypeError: 'function' object has no attribute '__getitem__'

I understand that DetailView does not have __getitem__. I also understand that __getitem__ is used for iteration. What I don't understand is why I am getting this error, or what to do about it. DetailView, which is supposed to be for a single object, so it must have some 'get' mechanism, and I see from ccbv.co.uk that it does, but then why is this traceback complaining about __getitem__? In other words, why is it looking for __getitem__ at all?

class CodeDetailView(DetailView):

    model = Code
    def get_context_data(self, **kwargs):
        context = super(CodeDetailView, self).get_context_data(**kwargs)
        template_name='statute_single.html'
        return context
        
Is this error really saying that I can't use DetailView where iteration is called for (as it is in my template)?

template

    <li><a href={% url 'family' 'slug' %}>{{ set_list }}</a></li>
    
I was trying to follow the code example from the docs, here:

https://docs.djangoproject.com/en/1.9/topics/class-based-views/generic-display/#adding-extra-context

(I know the extra context is not in the example posted)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/75c4fb09-3f5b-4222-93f7-b8bdb1ab2056%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment