Re: Search results in template

2017-12-26 Thread Malik Rumi
That appears to be it. I got content and all that on the simple template
this time.

I put values_list in there because that's the way it was done on the
postgres full text search tutorial I was using. I assumed it was needed for
rank, I never thought about it limiting me otherwise.
If I seem a little less enthused than I should be, it is only because I am
getting a little tired and hungry, and was emotionally prepared to put this
whole thing aside and had started working on something else.
But you have helped me tremendously, and I greatly appreciate it. Tomorrow
I will play with it some more... unless my mood changes after I eat  ;-)

THANK YOU

*“None of you has faith until he loves for his brother or his neighbor what
he loves for himself.”*

On Tue, Dec 26, 2017 at 9:19 PM, James Schneider 
wrote:

>
>
>
> *And the result:*
>
>
> !DOCTYPE This is the first page
>
>-
>
>('2017-10-09 Incentive, a further review', 0.151982)
>-
>
>('2017-11-14 Pulling The Trigger', 0.151982)
>-
>
>('2017-10-05 A Failure of Incentive?', 0.121585)
>-
>
>('2017-10-20 spider refactor', 0.121585) And now for something
>completely different...
>-
>
>   :
>   -
>
>   :
>   -
>
>   :
>   -
>
>   :
>   -
>
>
>
> <<>>
>
>
> So this looks like a variable problem, but I don't claim to understand
> that, either. I mentioned earlier on this thread that different variables
> gave me different results, but everyone says that can't be it.
>
>
>
> Ah. Are you still chaining .values_list() to your query in the view? That
> would explain the output above.
>
> The loop is built with the assumption that we have full objects from the
> ORM, but because we chained .value_list(), we're actually getting a list of
> tuples containing two values.
>
> Your templates are built in the same manner. Can you run the second loop
> again with .values_list() removed from the query in the view?
>
> -James
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/xSW1BjLXXSQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@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/CA%2Be%2BciWjdFDwUPT7-60Gk1OfaejZeoFAsDXZpgXjp0mQ26C
> 30g%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@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/CAKd6oBzskoyggu4LBHafufPXQ1QHeuNdQiUEZbD6zRO7-fGWOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search results in template

2017-12-26 Thread James Schneider
*And the result:*


!DOCTYPE This is the first page

   -

   ('2017-10-09 Incentive, a further review', 0.151982)
   -

   ('2017-11-14 Pulling The Trigger', 0.151982)
   -

   ('2017-10-05 A Failure of Incentive?', 0.121585)
   -

   ('2017-10-20 spider refactor', 0.121585) And now for something
   completely different...
   -

  :
  -

  :
  -

  :
  -

  :
  -



<<>>


So this looks like a variable problem, but I don't claim to understand
that, either. I mentioned earlier on this thread that different variables
gave me different results, but everyone says that can't be it.



Ah. Are you still chaining .values_list() to your query in the view? That
would explain the output above.

The loop is built with the assumption that we have full objects from the
ORM, but because we chained .value_list(), we're actually getting a list of
tuples containing two values.

Your templates are built in the same manner. Can you run the second loop
again with .values_list() removed from the query in the view?

-James

-- 
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+unsubscr...@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/CA%2Be%2BciWjdFDwUPT7-60Gk1OfaejZeoFAsDXZpgXjp0mQ26C30g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search results in template

2017-12-26 Thread Malik Rumi
*Your first suggested loop:*

This is the first page



{% for obj in QuerySet %}

{{obj}}

{% empty %}

No results

{% endfor %}

*The result:*

!DOCTYPE This is the first page

   -

   ('2017-10-09 Incentive, a further review', 0.151982)
   -

   ('2017-11-14 Pulling The Trigger', 0.151982)
   -

   ('2017-10-05 A Failure of Incentive?', 0.121585)
   -

   ('2017-10-20 spider refactor', 0.121585)


*Same template with your second loop added:*


!DOCTYPE








This is the first page




{% for obj in QuerySet %}

{{obj}}

{% empty %}

No results

{% endfor %}


And now for something completely different...




{% for obj in QuerySet %}

{{obj.title}}: {{obj.chron_date}}

{{obj.content}}

{% empty %}

No results

{% endfor %}







*And the result:*


!DOCTYPE This is the first page

   -

   ('2017-10-09 Incentive, a further review', 0.151982)
   -

   ('2017-11-14 Pulling The Trigger', 0.151982)
   -

   ('2017-10-05 A Failure of Incentive?', 0.121585)
   -

   ('2017-10-20 spider refactor', 0.121585) And now for something
   completely different...
   -

  :
  -

  :
  -

  :
  -

  :
  -



<<>>


So this looks like a variable problem, but I don't claim to understand
that, either. I mentioned earlier on this thread that different variables
gave me different results, but everyone says that can't be it.

*“None of you has faith until he loves for his brother or his neighbor what
he loves for himself.”*

On Tue, Dec 26, 2017 at 8:34 PM, Malik Rumi  wrote:

> Here is the Entry model:
>
> class Entry(models.Model):
> title = models.CharField(max_length=100, blank=False, null=False)
> slug = models.SlugField(max_length=100)
> content = models.TextField()
> posted_date = models.DateTimeField(auto_now=True)
> chron_date = models.DateField(auto_now=False, auto_now_add=False,
> blank=True)
> clock = models.TimeField(auto_now=False, auto_now_add=False,
> blank=True)
>
> ALIGN = "Align"
> CULTURE = "Culture"
> EXPENSE = "Expense"
> INCOME = "Income"
> HUMAN_RELATIONSHIPS = "Human Relationships"
> CATEGORY_CHOICES = (
> (ALIGN, "Align"),
> (CULTURE, "Culture"),
> (EXPENSE, "Expense"),
> (INCOME, "Income"),
> (HUMAN_RELATIONSHIPS, "Human Relationships"),
> )
> category = models.CharField(max_length=25, choices=CATEGORY_CHOICES,
> default=INCOME)
> tags = models.ManyToManyField(Tag)
> search_vector = SearchVectorField(blank=True, null=True)
>
> class Meta:
> verbose_name = "Diary Entry"
> verbose_name_plural = "Diary Entries"
> ordering = ["-chron_date", "clock"]
> indexes = [
> GinIndex(fields=['search_vector'])
> ]
>
> def __str__(self):
> return self.title
>
> def get_absolute_url(self):
> return reverse('detail', kwargs={"slug": self.slug})
>
>
> You already have the template in my original post to start this thread.
>
> *“None of you has faith until he loves for his brother or his neighbor
> what he loves for himself.”*
>
> On Tue, Dec 26, 2017 at 2:26 PM, James Schneider 
> wrote:
>
>>
>>
>>
>> The template context says I have a queryset
>>
>>
>> I see it there. Can you post up the model for Entry?
>>
>>
>>
>>
>> And so does the selection
>>
>>
>> Yes. It appears that you will have 4 results in your queryset.
>>
>>
>>
>> I put print statements in the view:
>>
>> ##
>> Quit the server with CONTROL-C.
>> This is the value of query:  SearchQuery(eaa)
>> This is the value of QuerySet:  > further review', 0.151982), ('2017-11-14  Pulling The Trigger', 0.151982),
>> ('2017-10-05 A Failure of Incentive?', 0.121585), ('2017-10-20 spider
>> refactor', 0.121585)]>
>> [26/Dec/2017 18:57:31] "GET /serp/?q=eaa HTTP/1.1" 200 66580
>>
>> ##
>>
>>
>> At this point, the view doesn't appear to be the problem. We need to
>> start tracking things down in the template code.
>>
>>
>>
>>
>> Note this is all done through my simple html search form, defined in the
>> template. My Django Form, SearchBox(), does absolutely nothing, as if it
>> isn't connected to anything. I don't understand what the problem there is,
>> I can't show that this is related or not. I do know I'd rather have the
>> functionality than a pretty form.
>>
>>
>> No reason you can't have both, but let's work on the result display issue
>> first.
>>
>> An ordinary ListView of all objects works normally, as does my
>> DetailView. I have tried several times to re-write views.serp as a cbv with
>> get_context_data, but either context or request or Searchbox() end up being
>> undefined, or an ImportError.
>>
>>
>> Are you overriding get_context_data() correctly? It doesn't sound like it.
>>
>>
>> Finally, a screenshot of my search page, with four spaces for the 4
>> entries that correctly correspond to the query 'eaa'. They just aren't
>> there.
>>
>>
>> This is where the problem is, I think.
>>
>> You should set up a simple loop in your 

Re: Search results in template

2017-12-26 Thread Malik Rumi
Here is the Entry model:

class Entry(models.Model):
title = models.CharField(max_length=100, blank=False, null=False)
slug = models.SlugField(max_length=100)
content = models.TextField()
posted_date = models.DateTimeField(auto_now=True)
chron_date = models.DateField(auto_now=False, auto_now_add=False,
blank=True)
clock = models.TimeField(auto_now=False, auto_now_add=False, blank=True)

ALIGN = "Align"
CULTURE = "Culture"
EXPENSE = "Expense"
INCOME = "Income"
HUMAN_RELATIONSHIPS = "Human Relationships"
CATEGORY_CHOICES = (
(ALIGN, "Align"),
(CULTURE, "Culture"),
(EXPENSE, "Expense"),
(INCOME, "Income"),
(HUMAN_RELATIONSHIPS, "Human Relationships"),
)
category = models.CharField(max_length=25, choices=CATEGORY_CHOICES,
default=INCOME)
tags = models.ManyToManyField(Tag)
search_vector = SearchVectorField(blank=True, null=True)

class Meta:
verbose_name = "Diary Entry"
verbose_name_plural = "Diary Entries"
ordering = ["-chron_date", "clock"]
indexes = [
GinIndex(fields=['search_vector'])
]

def __str__(self):
return self.title

def get_absolute_url(self):
return reverse('detail', kwargs={"slug": self.slug})


You already have the template in my original post to start this thread.

*“None of you has faith until he loves for his brother or his neighbor what
he loves for himself.”*

On Tue, Dec 26, 2017 at 2:26 PM, James Schneider 
wrote:

>
>
>
> The template context says I have a queryset
>
>
> I see it there. Can you post up the model for Entry?
>
>
>
>
> And so does the selection
>
>
> Yes. It appears that you will have 4 results in your queryset.
>
>
>
> I put print statements in the view:
>
> ##
> Quit the server with CONTROL-C.
> This is the value of query:  SearchQuery(eaa)
> This is the value of QuerySet:   further review', 0.151982), ('2017-11-14  Pulling The Trigger', 0.151982),
> ('2017-10-05 A Failure of Incentive?', 0.121585), ('2017-10-20 spider
> refactor', 0.121585)]>
> [26/Dec/2017 18:57:31] "GET /serp/?q=eaa HTTP/1.1" 200 66580
>
> ##
>
>
> At this point, the view doesn't appear to be the problem. We need to start
> tracking things down in the template code.
>
>
>
>
> Note this is all done through my simple html search form, defined in the
> template. My Django Form, SearchBox(), does absolutely nothing, as if it
> isn't connected to anything. I don't understand what the problem there is,
> I can't show that this is related or not. I do know I'd rather have the
> functionality than a pretty form.
>
>
> No reason you can't have both, but let's work on the result display issue
> first.
>
> An ordinary ListView of all objects works normally, as does my DetailView.
> I have tried several times to re-write views.serp as a cbv with
> get_context_data, but either context or request or Searchbox() end up being
> undefined, or an ImportError.
>
>
> Are you overriding get_context_data() correctly? It doesn't sound like it.
>
>
> Finally, a screenshot of my search page, with four spaces for the 4
> entries that correctly correspond to the query 'eaa'. They just aren't
> there.
>
>
> This is where the problem is, I think.
>
> You should set up a simple loop in your template:
>
> 
> {% for obj in QuerySet %}
> {{obj}}
> {% empty %}
> No results
> {% endfor %}
>
> If that works, you should go deeper per your Entry model:
>
>
> 
> {% for obj in QuerySet %}
> {{obj.name}}: {{obj.weight}}
> {% empty %}
> No results
> {% endfor %}
>
> I'm using name and weight as an attribute of Entry, but you should use
> something that matches your model definition. I think the issue is that you
> are not referring to your model correctly within the search results within
> the template.
>
> -James
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/xSW1BjLXXSQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@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/CA%2Be%2BciWvgD7-RnqWJvpKrpYvd2SB2TGwOW2bj4UOcK
> btMJVR%3Dg%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to d

Re: Search results in template

2017-12-26 Thread James Schneider
The template context says I have a queryset


I see it there. Can you post up the model for Entry?




And so does the selection


Yes. It appears that you will have 4 results in your queryset.



I put print statements in the view:

##
Quit the server with CONTROL-C.
This is the value of query:  SearchQuery(eaa)
This is the value of QuerySet:  
[26/Dec/2017 18:57:31] "GET /serp/?q=eaa HTTP/1.1" 200 66580

##


At this point, the view doesn't appear to be the problem. We need to start
tracking things down in the template code.




Note this is all done through my simple html search form, defined in the
template. My Django Form, SearchBox(), does absolutely nothing, as if it
isn't connected to anything. I don't understand what the problem there is,
I can't show that this is related or not. I do know I'd rather have the
functionality than a pretty form.


No reason you can't have both, but let's work on the result display issue
first.

An ordinary ListView of all objects works normally, as does my DetailView.
I have tried several times to re-write views.serp as a cbv with
get_context_data, but either context or request or Searchbox() end up being
undefined, or an ImportError.


Are you overriding get_context_data() correctly? It doesn't sound like it.


Finally, a screenshot of my search page, with four spaces for the 4 entries
that correctly correspond to the query 'eaa'. They just aren't there.


This is where the problem is, I think.

You should set up a simple loop in your template:


{% for obj in QuerySet %}
{{obj}}
{% empty %}
No results
{% endfor %}

If that works, you should go deeper per your Entry model:



{% for obj in QuerySet %}
{{obj.name}}: {{obj.weight}}
{% empty %}
No results
{% endfor %}

I'm using name and weight as an attribute of Entry, but you should use
something that matches your model definition. I think the issue is that you
are not referring to your model correctly within the search results within
the template.

-James

-- 
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+unsubscr...@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/CA%2Be%2BciWvgD7-RnqWJvpKrpYvd2SB2TGwOW2bj4UOcKbtMJVR%3Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search results in template

2017-12-26 Thread Malik Rumi
PyCharm had my project running in a separate process. Don't worry about
that. I don't think it's a huge issue


I have the right view


The template context says I have a queryset


The explanation seems right.


And so does the selection

I put print statements in the view:

##
Quit the server with CONTROL-C.
This is the value of query:  SearchQuery(eaa)
This is the value of QuerySet:  
[26/Dec/2017 18:57:31] "GET /serp/?q=eaa HTTP/1.1" 200 66580

##

Note this is all done through my simple html search form, defined in the
template. My Django Form, SearchBox(), does absolutely nothing, as if it
isn't connected to anything. I don't understand what the problem there is,
I can't show that this is related or not. I do know I'd rather have the
functionality than a pretty form.

An ordinary ListView of all objects works normally, as does my DetailView.
I have tried several times to re-write views.serp as a cbv with
get_context_data, but either context or request or Searchbox() end up being
undefined, or an ImportError.

Finally, a screenshot of my search page, with four spaces for the 4 entries
that correctly correspond to the query 'eaa'. They just aren't there.






😪



*“None of you has faith until he loves for his brother or his neighbor what
he loves for himself.”*

On Sun, Dec 24, 2017 at 2:44 AM, James Schneider 
wrote:

>
>
> 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 a

Re: Search results in template

2017-12-24 Thread James Schneider
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?

-James

-- 
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+unsubscr...@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/CA%2Be%2BciX3a%3D3O9AGv4hF5bff0xD7L8mCrkrrW0nKvRtNCzZ3UxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search results in template

2017-12-23 Thread Malik Rumi
FIRST, James, let me say how much I *greatly* appreciate you hanging in
there and trying to help me.
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.

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.

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!



*“None of you has faith until he loves for his brother or his neighbor what
he loves for himself.”*

On Fri, Dec 22, 2017 at 4:31 PM, James Schneider 
wrote:

>
> 
>> 
>>  
>>  {% for object in object_list %}
>>  {{ object.title 
>> }}
>>  
>>  
>>  
>>  > class="day">{{object.chron_date}}
>>  > class="month">{{object.clock}} 
>>  
>>  by > href="#">
>>  22 
>> comments
>>  
>>  
>>  
>>  {{ object.content|truncatewords:30 }}
>>  
>>  > class="icon-tags"> tag 1, tag 2, > href="#">long tag 3
>>  Read More
>>  
>> 
>>  
>>  {% endfor %}
>> Any assistance in getting the search results to show up greatly 
>> appreciated.--
>>
>>
> There is still an issue with the HTML from what I can see, your {% for %}
> loop starts within an  tag, but the  tag is within the
> {% for %} loop, so you are trying to create multiple article entries, but
> only the first has an opening  tag. Not sure how/if that affects
> the display of the results.
>
> The point from my previous goof still stands, do your results show within
> the rendered page HTML, but just aren't being displayed?
>
> -James
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/xSW1BjLXXSQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@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/CA%2Be%2BciV56ORGwDeap7nser4RwSE3gdZV
> XPgREMU%3Dzw8g6YDx2g%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop 

Re: Search results in template

2017-12-22 Thread James Schneider
> 
> 
>   
>   {% for object in object_list %}
>   {{ object.title 
> }}
>   
>   
>   
>class="day">{{object.chron_date}}
>class="month">{{object.clock}} 
>   
>  by 
>  22 
> comments
>   
>   
>   
>   {{ object.content|truncatewords:30 }}
>   
>class="icon-tags"> tag 1, tag 2,  href="#">long tag 3
>   Read More
>   
> 
>   
>   {% endfor %}
> Any assistance in getting the search results to show up greatly appreciated.--
>
>
There is still an issue with the HTML from what I can see, your {% for %}
loop starts within an  tag, but the  tag is within the
{% for %} loop, so you are trying to create multiple article entries, but
only the first has an opening  tag. Not sure how/if that affects
the display of the results.

The point from my previous goof still stands, do your results show within
the rendered page HTML, but just aren't being displayed?

-James

-- 
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+unsubscr...@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/CA%2Be%2BciV56ORGwDeap7nser4RwSE3gdZVXPgREMU%3Dzw8g6YDx2g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search results in template

2017-12-22 Thread James Schneider
Here's your problem. Your results are being entered in to your header and
not in to the body of the HTML. I bet if you look at the source code of the
rendered page, they're all there.


Scratch that, I'm thinking of  not .

-- 
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+unsubscr...@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/CA%2Be%2BciUUj6heJuggh%2BVmsqKOJojupLgS1chQjn7eqLMs1u9uxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search results in template

2017-12-22 Thread James Schneider



{% for object in object_list %}
{{ object.title 
}}



Here's your problem. Your results are being entered in to your header and
not in to the body of the HTML. I bet if you look at the source code of the
rendered page, they're all there.

-James

-- 
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+unsubscr...@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/CA%2Be%2BciXhETi9wDRgDSiRKkpT4QoTrPA%3Dpt_KJzU1JZ-K2uTGVA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search results in template

2017-12-22 Thread Malik Rumi
Thanks to both of you. The template context is what it should be, and 
putting all the view in the same block made no difference. :-(

On Wednesday, December 20, 2017 at 6:24:57 AM UTC-8, James Schneider wrote:
>
>
>
> On Dec 19, 2017 5:12 PM, "Malik Rumi" > 
> wrote:
>
> I am implementing search on a local Django project: Django 1.11.5, Python 
> 3.6.3, Ubuntu 16.04. My issue is getting the search results onto the 
> template.
>
> I am using standard CBV for everything else in the site, but for this one 
> I wrote my own. It uses the same template as my ListView, which shows all 
> objects fine.
>
>
>
> def serp(request):
> if request.method == 'GET' and 'searchbox' in request.GET:
> q = request.GET.get('searchbox')
> query = SearchQuery(q)
> object_list = Entry.objects.annotate(
> rank=SearchRank(F(
> 'search_vector'), query)).filter(
> search_vector=query).order_by(
> '-rank').values_list('title', 'rank')
> return render(request, 'serp_list.html', {'object_list': object_list})
>
>
> Django Debug Toolbar reports everything went as expected. The right 
> template and view were called, as well as the right db query. I had 
> previously tested this query in the shell, and it pulls up a 4 element 
> queryset, as it should. 
>
>
> Your view has a bug. If the first 'if' statement returns false, then the 
> view fails because the 'q' variable is never set, and your viewer will get 
> a 500 error. I think the two lines following the 'q =' line should be 
> indented inside of the if statement, and object_list should be set to an 
> empty list by default before the 'if' statement.
>
> You should also ensure that this view is the one that is actually being 
> called by the URL dispatcher.
>
> Checking what is in the template context with the DDT is the next step. If 
> the template context is incorrect, then you'll need to debug within your 
> view to determine where/why the context is not being set correctly.
>
> 'object_list' is a generic variable name used by list CBV's in the 
> template context, but should be available to FBV's since there is no magic 
> context creation.
>
> -James
>

-- 
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+unsubscr...@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/943dcc6f-01a8-4ef2-a784-3b503b1b5c38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search results in template

2017-12-20 Thread James Schneider
On Dec 19, 2017 5:12 PM, "Malik Rumi"  wrote:

I am implementing search on a local Django project: Django 1.11.5, Python
3.6.3, Ubuntu 16.04. My issue is getting the search results onto the
template.

I am using standard CBV for everything else in the site, but for this one I
wrote my own. It uses the same template as my ListView, which shows all
objects fine.



def serp(request):
if request.method == 'GET' and 'searchbox' in request.GET:
q = request.GET.get('searchbox')
query = SearchQuery(q)
object_list = Entry.objects.annotate(
rank=SearchRank(F(
'search_vector'), query)).filter(
search_vector=query).order_by(
'-rank').values_list('title', 'rank')
return render(request, 'serp_list.html', {'object_list': object_list})


Django Debug Toolbar reports everything went as expected. The right
template and view were called, as well as the right db query. I had
previously tested this query in the shell, and it pulls up a 4 element
queryset, as it should.


Your view has a bug. If the first 'if' statement returns false, then the
view fails because the 'q' variable is never set, and your viewer will get
a 500 error. I think the two lines following the 'q =' line should be
indented inside of the if statement, and object_list should be set to an
empty list by default before the 'if' statement.

You should also ensure that this view is the one that is actually being
called by the URL dispatcher.

Checking what is in the template context with the DDT is the next step. If
the template context is incorrect, then you'll need to debug within your
view to determine where/why the context is not being set correctly.

'object_list' is a generic variable name used by list CBV's in the template
context, but should be available to FBV's since there is no magic context
creation.

-James

-- 
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+unsubscr...@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/CA%2Be%2BciUMp_1%2B7b%2BdOa7Xej5r4f1F%2B514Qh4%3Dsr2ue5%3DwpXAcFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search results in template

2017-12-19 Thread Matemática A3K
On Tue, Dec 19, 2017 at 10:12 PM, Malik Rumi  wrote:

> I am implementing search on a local Django project: Django 1.11.5, Python
> 3.6.3, Ubuntu 16.04. My issue is getting the search results onto the
> template.
>
> I am using standard CBV for everything else in the site, but for this one
> I wrote my own. It uses the same template as my ListView, which shows all
> objects fine.
>
>
>
> def serp(request):
> if request.method == 'GET' and 'searchbox' in request.GET:
> q = request.GET.get('searchbox')
> query = SearchQuery(q)
> object_list = Entry.objects.annotate(
> rank=SearchRank(F(
> 'search_vector'), query)).filter(
> search_vector=query).order_by(
> '-rank').values_list('title', 'rank')
> return render(request, 'serp_list.html', {'object_list': object_list})
>
>
> Django Debug Toolbar reports everything went as expected. The right
> template and view were called, as well as the right db query. I had
> previously tested this query in the shell, and it pulls up a 4 element
> queryset, as it should.
>
> Even though no search results show on the page, there are 4 instances of
> the html that should be surrounding each result and rows=4 loops=1 in the
> query plan.
>
> One thing I found curious is that the **mere change** in the variable name 
> 'object_list' to 'resultslist' gave me no db query! I had always thought 
> variable names didn't matter in Python,
>
> but apparently 'object_list' is virtually a reserved word when it comes to 
> views (even FBVs) and templates in Django?
>
>
No, it is not a reserved keyword, the thing is by convention, CBV's
Listview (and others with MultipleObjectsMixin) makes available in that
variable the objects retrieved the view. It's a convention so you can
easily reuse code. What is important is the name you pass to the template,

{**'object_list'**: your_retrieved_objects}

 as it expects that. If nothing evaluates the variable which contains your
query / queryset results, it might be never executed - is that your doubt?

>  Here is the template:
>
> 
> 
>   
>   {% for object in object_list %}
>   {{ object.title 
> }}
>   
>   
>   
>class="day">{{object.chron_date}}
>class="month">{{object.clock}} 
>   
>  by 
>  22 
> comments
>   
>   
>   
>   {{ object.content|truncatewords:30 }}
>   
>class="icon-tags"> tag 1, tag 2,  href="#">long tag 3
>   Read More
>   
> 
>   
>   {% endfor %}
> Any assistance in getting the search results to show up greatly appreciated.
>
>
Your code seems fine, it seems that the object_list is not getting to the
context of the Template and the "for" is not executing due to an empty
object_list. I don't remember where is it in DDT, but there is a place
where it shows the context for the Template, look for there if there is no
empty (or not defined) "object_list"

HTH


> --
>
> ps -
>
>
> Despite the 99% similarity, this is not identical to my issue in
> https://groups.google.com/forum/#!searchin/django-users/
> template%7Csort:relevance/django-users/o4UKSTBtwyg/cU4JeRJHHgAJ There I
> had the for variable 'i' but put the name of the list in the {{regular
> variables}}. That is not the issue this time, but clearly I have trouble
> grasping the regular and efficient use of Django context and templates. And
> yes, I have looked at the docs as well as elsewhere. So if, in addition to
> an answer, you can point me to a real clear, simple, step by step primer on
> making these two things work together, I would gladly look at it.
>
>
>
>
>
>
>
>
>
> -
>
> --
> 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+unsubscr...@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/6670bc0d-9f64-4b6f-9f62-a007d969e0b9%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@goog

Search results in template

2017-12-19 Thread Malik Rumi
 

I am implementing search on a local Django project: Django 1.11.5, Python 
3.6.3, Ubuntu 16.04. My issue is getting the search results onto the 
template.

I am using standard CBV for everything else in the site, but for this one I 
wrote my own. It uses the same template as my ListView, which shows all 
objects fine.



def serp(request):
if request.method == 'GET' and 'searchbox' in request.GET:
q = request.GET.get('searchbox')
query = SearchQuery(q)
object_list = Entry.objects.annotate(
rank=SearchRank(F(
'search_vector'), query)).filter(
search_vector=query).order_by(
'-rank').values_list('title', 'rank')
return render(request, 'serp_list.html', {'object_list': object_list})


Django Debug Toolbar reports everything went as expected. The right 
template and view were called, as well as the right db query. I had 
previously tested this query in the shell, and it pulls up a 4 element 
queryset, as it should. 

Even though no search results show on the page, there are 4 instances of 
the html that should be surrounding each result and rows=4 loops=1 in the 
query plan. 

One thing I found curious is that the **mere change** in the variable name 
'object_list' to 'resultslist' gave me no db query! I had always thought 
variable names didn't matter in Python, 

but apparently 'object_list' is virtually a reserved word when it comes to 
views (even FBVs) and templates in Django? Here is the template:




{% for object in object_list %}
{{ object.title 
}}



{{object.chron_date}}
{{object.clock}} 

 by 
 22 
comments



{{ object.content|truncatewords:30 }}

 tag 1, tag 2, long tag 3
Read More



{% endfor %}
Any assistance in getting the search results to show up greatly appreciated.--

ps -


Despite the 99% similarity, this is not identical to my issue in 
https://groups.google.com/forum/#!searchin/django-users/template%7Csort:relevance/django-users/o4UKSTBtwyg/cU4JeRJHHgAJ
 
There I had the for variable 'i' but put the name of the list in the 
{{regular variables}}. That is not the issue this time, but clearly I have 
trouble grasping the regular and efficient use of Django context and 
templates. And yes, I have looked at the docs as well as elsewhere. So if, 
in addition to an answer, you can point me to a real clear, simple, step by 
step primer on making these two things work together, I would gladly look 
at it.  









-

-- 
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+unsubscr...@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/6670bc0d-9f64-4b6f-9f62-a007d969e0b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.