Sunday, December 24, 2017

Re: Search results in template

On Dec 23, 2017 5:36 PM, "Malik Rumi" <> wrote:
FIRST, James, let me say how much I greatly appreciate you hanging in there and trying to help me.

No worries.

2nd, as to your two points about the html:
   a. This template, serp_list.html, is identical to ktab_list.html, except that serp_list has the title 'SEARCH' at the top and some bolierplate text about this being the search results page. Other than that they are identical, including the template for loop. 
       serp_list is supposed to be called by localhost/serp/, which points to views.serp, which is an FBV. 
       ktab_list is a vanilla implementation of ListView, called by localhost/index/, and it shows all Entry objects as you would expect.  
       The header you see is the blog post header, ie, this is where the title and the get absoulte url to the detail page is supposed to go. On /index/ that works like it should. On serp, well, that's why I am here.
  b. Your second point is probably well taken, that the for loop should completely wrap the article, and that might explain why the author and comments part of the last three posts were not the same font as the first post. I have changed that in the html, but it has not changed the result. 

Hooray, at least I've gotten something right. ;-

3rd, just because things weren't complicated enough, now I am getting inconsistent results. Whereas before I got views.serp called, a db query with 4 results, on the right template, now I am getting a value error ('returns None' - how's that for a news flash?). The only difference is that I downloaded the free version of pycharm to see if their visual debugger would help me. So calling the page through pycharm, instead of the regular terminal, is the only difference, and I don't think that should make a difference. But either way, I still have no result on my page - and oh yea, pycharm says the same thing my print statements did - that the query was there and pulled up the expected objects. They just won't show up on the template. 

Confused. You mentioned PyCharm affected the results but then indicated the same results?

4th, I don't know how relevant this is, but the form which created the search box has the form action = '/serp/', but despite that, if I use the search box in /index/, I stay on /index/ and just get the query attached to the end of that url, rather than /serp/ plus the query. I have to manually type in /serp/ to get  views.serp called. When it stays on  /index/ plus the query, the result shown are just Entry.objects.all(), as you would expect on a ListView. Any thoughts on that? Is it related? Why isn't my form action working? THANKS!

A few (possibly dumb) questions:

Have you verified that the serp.html page is the one actually being rendered? DDT can verify this.

Have you confirmed the context being provided to the template actually contains the variables and query results you are expecting? DDT can also verify this.

Can you do something simple like {{ object_list }} in your template just to see if anything is printed? When doing quick troubleshooting I like to do this:

|{{ object_list }}|

That way if I see || in the template (and source), I know the variable is empty.

Do you have any non-standard middleware or template context processors enabled?

Are your forms set to use a method of GET or POST? Sounds like GET but just want to verify.

When you are on /index/ and you search, does the runserver console show a hit against /serp/ (per the form action) or is it simply a hit against /index/ again? Or is there a redirect for some reason?


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
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment