class SimpleSearchListContactView(ListView):
model = Contact
template_name = 'contacts/contact_list.html'
def get_queryset(self):
qs = super(SimpleSearchListContactView, self).get_queryset()
return qs.filter(first_name__contains=self.kwargs['fname'])
# "first_name" is the first_name field in our Contacts model
# "contains" is one of Django's "Field lookups"
# "'fname'" is passed in from our url <fname> Regex Named Group
class ParametricSearchListContactView(ListView):
model = Contact
template_name = 'contacts/contact_list.html'
def get_queryset(self):
qs = super(ParametricSearchListContactView, self).get_queryset()
field_lookups_dict = {
'%s__%s'%(self.kwargs['field_name'], self.kwargs['match_cmd']):self.kwargs['value'],
# for a def of each match_cmd see Field lookups - https://docs.djangoproject.com/en/1.9/ref/models/querysets/#field-lookups
}
print ("ParametricSearchListContactView")
print (ParametricSearchCRUDListContactView.template_name)
print (ParametricSearchListContactView.template_name)
print (ListView.template_name)
return qs.filter(**field_lookups_dict)
class SimpleSearchCRUDListContactView(ListView):
model = Contact
template_name = 'contacts/crudlist.htm'
def get_queryset(self):
qs = super(SimpleSearchCRUDListContactView, self).get_queryset()
return qs.filter(first_name__contains=self.kwargs['fname'])
# "first_name" is the first_name field in our Contacts model
# "contains" is one of Django's "Field lookups"
# "'fname'" is passed in from our url <fname> Regex Named Group
class ParametricSearchCRUDListContactView(ListView):
model = Contact
template_name = 'contacts/crudlist.htm'
def get_queryset(self):
qs = super(ParametricSearchCRUDListContactView, self).get_queryset()
field_lookups_dict = {
'%s__%s'%(self.kwargs['field_name'], self.kwargs['match_cmd']):self.kwargs['value'],
# for a def of each match_cmd see Field lookups - https://docs.djangoproject.com/en/1.9/ref/models/querysets/#field-lookups
}
print ("ParametricSearchCRUDListContactView")
print (ParametricSearchCRUDListContactView.template_name)
print (ParametricSearchListContactView.template_name)
print (ListView.template_name)
return qs.filter(**field_lookups_dict)
url(r'^ssearch/(?P<fname>[\w-]+)/$', contacts.views.SimpleSearchListContactView.as_view(), name='simplesearchlistcontactview', ),
url(r'^psearch/(?P<field_name>[\w-]+)/(?P<match_cmd>[\w-]+)/(?P<value>[\w-]+)/$', contacts.views.ParametricSearchListContactView.as_view(), name='parametricsearchlistcontactview', ),
url(r'^ssearchc/(?P<fname>[\w-]+)/$', contacts.views.SimpleSearchCRUDListContactView.as_view(), name='ssearchc', ),
url(r'^psearchc/(?P<field_name>[\w-]+)/(?P<match_cmd>[\w-]+)/(?P<value>[\w-]+)/$', contacts.views.ParametricSearchCRUDListContactView.as_view(), name='psearchc', ),
contacts/crudlist.htm
` displays them.contacts/contact_list.html
) NOT the CRUD Template ('contacts/crudlist.htm'
)NOT AS EXPECTED
[18/Jun/2016 11:16:26] "GET /contacts/psearchc/last_name/contains/d/ HTTP/1.1" 200 218
ParametricSearchCRUDListContactView
contacts/crudlist.htm
contacts/contact_list.html
None
> I EXPECT the Views with CRUD in their names (CRUD Views) to behave THE SAME AS the others EXCEPT items are listed with read, update & delete links, because that is how `contacts/crudlist.htm` displays them.
>
> THE PROBLEM IS that the CRUD Views display the items using the Plain Template (contacts/contact_list.html) NOT the CRUD Template ('contacts/crudlist.htm')
>
The Django debug toolbar can likely illuminate the problem here, or at least provide a direction. You would need to verify the template(s) that have been rendered as part of your view call, and that they're actually doing what you think they're doing.
It's a bit hard to follow your code, as you include extraneous classes that don't appear to be relevant to the problem (no inheritance, no indication they've been triggered, etc.). With that being said, your output from the view appears to be correct and shows a different (and correct) template_name for each view. I might be missing something though, and admittedly I'm responding on my phone.
My assumption at this point would be that the templates are rendered correctly by Django (correctly meaning 'as configured'), and that the issue actually lies within your template inheritance structure (if any). Again, the debug toolbar will walk you through that.
-James
I'll investigate the Debug Toolbar & see what it tells me.
Again, THANKS, BIG TIME, James.
Love and peace,
Joe
{'False': False, 'None': None, 'True': True}
{'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10,
'ERROR': 40,
'INFO': 20,
'SUCCESS': 25,
'WARNING': 30},
'csrf_token': <SimpleLazyObject: '8EMBPVWQwGxM4RqYdoUYNbLZcdGX3Wyo'>,
'debug': True,
'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x000001E614D9C8D0>,
'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x000001E614D91940>,
'request': '<<request>>',
'sql_queries': <function debug.<locals>.<lambda> at 0x000001E614DA7A60>,
'user': <SimpleLazyObject: <User: joeco>>}
{}
{'contact_list': '<<queryset of contacts.Contact>>',
'is_paginated': False,
'object_list': '<<queryset of contacts.Contact>>',
'page_obj': None,
'paginator': None,
'view': <contacts.views.ParametricSearchCRUDListContactView object at 0x000001E614D9C278>}
{'csrf_token': <SimpleLazyObject: '8EMBPVWQwGxM4RqYdoUYNbLZcdGX3Wyo'>}
{'sql_queries': <function debug.<locals>.<lambda> at 0x000001E614DA7A60>, 'debug': True}
{'request': <WSGIRequest: GET '/contacts/psearchc/last_name/contains/d/'>}
{'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x000001E614D91940>, 'user': <SimpleLazyObject: <User: joeco>>}
{'DEFAULT_MESSAGE_LEVELS': {'INFO': 20, 'WARNING': 30, 'DEBUG': 10, 'ERROR': 40, 'SUCCESS': 25}, 'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x000001E614D9C8D0>}
contacts/crudlist.htm'
;contacts/contact_list.html'
OK EVERYONE, I APOLOGIZE. I HAD A SPELLING MISTAKE.
'contacts/crudlist.htm'
SHOULD HAVE BEEN
'contacts/crudlist.html'
All WORKS NOW.
THANKS for the help.
At least i found out about the Django Debug Toolbar.
Sorry again.
Thanks AGAIN.
Dear James & Django-Users,
As an afterthought, I wonder why my misspelling didn't cause an error instead of a "wrong" Template being used?
Any insights?
I'd be interested to see what the debug toolbar had to say while the typo was in place.
As an afterthought, I wonder why my misspelling didn't cause an error instead of a "wrong" Template being used?
Any insights?Not particularly. That should have caused an error. The only way it wouldn't have is if you have (or one of your installed apps has) a file named crudlist.htm inside of a folder named contacts. I'd be interested to see what the debug toolbar had to say while the typo was in place.As far as your question about template inheritance earlier, here is the link to the docs:-James