Django truncatewords and shows the searched wordWhat is a “slug” in Django?Django - Set Up A Scheduled Job?How do I do a not equal in Django queryset filtering?Does Django scale?Split Strings into words with multiple word boundary delimitersHow to debug in Django, the good way?How to check Django versiondifferentiate null=True, blank=True in djangoSplit JSON data into multiple files using PythonExtract the line by matching the word in a text file
How to find program name(s) of an installed package?
How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?
Why can't I see bouncing of a switch on an oscilloscope?
Expeditious Retreat
Why are 150k or 200k jobs considered good when there are 300k+ births a month?
Is it important to consider tone, melody, and musical form while writing a song?
Adding span tags within wp_list_pages list items
Why don't electron-positron collisions release infinite energy?
Why, historically, did Gödel think CH was false?
Why does Kotter return in Welcome Back Kotter?
Font hinting is lost in Chrome-like browsers (for some languages )
Why do falling prices hurt debtors?
Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)
How does one intimidate enemies without having the capacity for violence?
Is it unprofessional to ask if a job posting on GlassDoor is real?
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
What typically incentivizes a professor to change jobs to a lower ranking university?
How old can references or sources in a thesis be?
Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?
To string or not to string
Is this a crack on the carbon frame?
Is a tag line useful on a cover?
strToHex ( string to its hex representation as string)
Maximum likelihood parameters deviate from posterior distributions
Django truncatewords and shows the searched word
What is a “slug” in Django?Django - Set Up A Scheduled Job?How do I do a not equal in Django queryset filtering?Does Django scale?Split Strings into words with multiple word boundary delimitersHow to debug in Django, the good way?How to check Django versiondifferentiate null=True, blank=True in djangoSplit JSON data into multiple files using PythonExtract the line by matching the word in a text file
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a variable sentences
contains:
"Page's web crawler began exploring the web in March 1996, with Page's own Stanford home page serving as the only starting point. To convert the backlink data that it gathered for a given web page into a measure of importance, Brin and Page developed the PageRank algorithm. While analyzing BackRub's output which, for a given URL, consisted of a list of backlinks ranked by importance the pair realized that a search engine based on PageRank would produce better results than existing techniques (existing search engines at the time essentially ranked results according to how many times the search term appeared on a page)."
Then, I use truncatewords in Django HTML to short the view of the sentences.
sentences
So, the result shows this:
"Page's web crawler began exploring the web in March 1996, with Page's own Stanford home page serving as the only starting point. To convert the backlink data that it . . ."
Actually, I want to show the truncatewords
result with a specific word, for example, "BackRub", so the result supposed to be:
"While analyzing BackRub's output which, for a given URL, consisted of a list of backlinks ranked by importance the pair realized that a search engine based on PageRank would produce . . ."
Are there any solutions?
Thank you
python django
add a comment |
I have a variable sentences
contains:
"Page's web crawler began exploring the web in March 1996, with Page's own Stanford home page serving as the only starting point. To convert the backlink data that it gathered for a given web page into a measure of importance, Brin and Page developed the PageRank algorithm. While analyzing BackRub's output which, for a given URL, consisted of a list of backlinks ranked by importance the pair realized that a search engine based on PageRank would produce better results than existing techniques (existing search engines at the time essentially ranked results according to how many times the search term appeared on a page)."
Then, I use truncatewords in Django HTML to short the view of the sentences.
sentences
So, the result shows this:
"Page's web crawler began exploring the web in March 1996, with Page's own Stanford home page serving as the only starting point. To convert the backlink data that it . . ."
Actually, I want to show the truncatewords
result with a specific word, for example, "BackRub", so the result supposed to be:
"While analyzing BackRub's output which, for a given URL, consisted of a list of backlinks ranked by importance the pair realized that a search engine based on PageRank would produce . . ."
Are there any solutions?
Thank you
python django
add a comment |
I have a variable sentences
contains:
"Page's web crawler began exploring the web in March 1996, with Page's own Stanford home page serving as the only starting point. To convert the backlink data that it gathered for a given web page into a measure of importance, Brin and Page developed the PageRank algorithm. While analyzing BackRub's output which, for a given URL, consisted of a list of backlinks ranked by importance the pair realized that a search engine based on PageRank would produce better results than existing techniques (existing search engines at the time essentially ranked results according to how many times the search term appeared on a page)."
Then, I use truncatewords in Django HTML to short the view of the sentences.
sentences
So, the result shows this:
"Page's web crawler began exploring the web in March 1996, with Page's own Stanford home page serving as the only starting point. To convert the backlink data that it . . ."
Actually, I want to show the truncatewords
result with a specific word, for example, "BackRub", so the result supposed to be:
"While analyzing BackRub's output which, for a given URL, consisted of a list of backlinks ranked by importance the pair realized that a search engine based on PageRank would produce . . ."
Are there any solutions?
Thank you
python django
I have a variable sentences
contains:
"Page's web crawler began exploring the web in March 1996, with Page's own Stanford home page serving as the only starting point. To convert the backlink data that it gathered for a given web page into a measure of importance, Brin and Page developed the PageRank algorithm. While analyzing BackRub's output which, for a given URL, consisted of a list of backlinks ranked by importance the pair realized that a search engine based on PageRank would produce better results than existing techniques (existing search engines at the time essentially ranked results according to how many times the search term appeared on a page)."
Then, I use truncatewords in Django HTML to short the view of the sentences.
sentences
So, the result shows this:
"Page's web crawler began exploring the web in March 1996, with Page's own Stanford home page serving as the only starting point. To convert the backlink data that it . . ."
Actually, I want to show the truncatewords
result with a specific word, for example, "BackRub", so the result supposed to be:
"While analyzing BackRub's output which, for a given URL, consisted of a list of backlinks ranked by importance the pair realized that a search engine based on PageRank would produce . . ."
Are there any solutions?
Thank you
python django
python django
asked Mar 8 at 4:17
Samudra Ajri KifliSamudra Ajri Kifli
445
445
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I think you should write your own template tag to solve this problem.
You can get the beginning of the sentence which contains a specific word and return string starting from there. Then you can truncate result as you did above. I believe it's not the best solution. But I think it's something that you can start with. See code and results below:
somewhere in templatetags
import re
from django import template
register = template.Library()
@register.filter
def findsentencebyword(sentence, word):
matches = re.search("([^.]*?" + word + ".*)", sentence)
if not matches:
return sentence
return matches.group()
then load and use it in your template like below
% load <templatetag> %
findsentencebyword:"BackRub"
Here is the result:
It works. Unfortunately, this filter causes the page to become slow to load the results. Hope there has any alternative. Overall, thanks for the option.
– Samudra Ajri Kifli
Mar 11 at 7:27
@SamudraAjriKifli it's because of regular expression
– Davit Tovmasyan
Mar 11 at 9:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056652%2fdjango-truncatewords-and-shows-the-searched-word%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you should write your own template tag to solve this problem.
You can get the beginning of the sentence which contains a specific word and return string starting from there. Then you can truncate result as you did above. I believe it's not the best solution. But I think it's something that you can start with. See code and results below:
somewhere in templatetags
import re
from django import template
register = template.Library()
@register.filter
def findsentencebyword(sentence, word):
matches = re.search("([^.]*?" + word + ".*)", sentence)
if not matches:
return sentence
return matches.group()
then load and use it in your template like below
% load <templatetag> %
findsentencebyword:"BackRub"
Here is the result:
It works. Unfortunately, this filter causes the page to become slow to load the results. Hope there has any alternative. Overall, thanks for the option.
– Samudra Ajri Kifli
Mar 11 at 7:27
@SamudraAjriKifli it's because of regular expression
– Davit Tovmasyan
Mar 11 at 9:00
add a comment |
I think you should write your own template tag to solve this problem.
You can get the beginning of the sentence which contains a specific word and return string starting from there. Then you can truncate result as you did above. I believe it's not the best solution. But I think it's something that you can start with. See code and results below:
somewhere in templatetags
import re
from django import template
register = template.Library()
@register.filter
def findsentencebyword(sentence, word):
matches = re.search("([^.]*?" + word + ".*)", sentence)
if not matches:
return sentence
return matches.group()
then load and use it in your template like below
% load <templatetag> %
findsentencebyword:"BackRub"
Here is the result:
It works. Unfortunately, this filter causes the page to become slow to load the results. Hope there has any alternative. Overall, thanks for the option.
– Samudra Ajri Kifli
Mar 11 at 7:27
@SamudraAjriKifli it's because of regular expression
– Davit Tovmasyan
Mar 11 at 9:00
add a comment |
I think you should write your own template tag to solve this problem.
You can get the beginning of the sentence which contains a specific word and return string starting from there. Then you can truncate result as you did above. I believe it's not the best solution. But I think it's something that you can start with. See code and results below:
somewhere in templatetags
import re
from django import template
register = template.Library()
@register.filter
def findsentencebyword(sentence, word):
matches = re.search("([^.]*?" + word + ".*)", sentence)
if not matches:
return sentence
return matches.group()
then load and use it in your template like below
% load <templatetag> %
findsentencebyword:"BackRub"
Here is the result:
I think you should write your own template tag to solve this problem.
You can get the beginning of the sentence which contains a specific word and return string starting from there. Then you can truncate result as you did above. I believe it's not the best solution. But I think it's something that you can start with. See code and results below:
somewhere in templatetags
import re
from django import template
register = template.Library()
@register.filter
def findsentencebyword(sentence, word):
matches = re.search("([^.]*?" + word + ".*)", sentence)
if not matches:
return sentence
return matches.group()
then load and use it in your template like below
% load <templatetag> %
findsentencebyword:"BackRub"
Here is the result:
answered Mar 8 at 6:43
Davit TovmasyanDavit Tovmasyan
1,2071820
1,2071820
It works. Unfortunately, this filter causes the page to become slow to load the results. Hope there has any alternative. Overall, thanks for the option.
– Samudra Ajri Kifli
Mar 11 at 7:27
@SamudraAjriKifli it's because of regular expression
– Davit Tovmasyan
Mar 11 at 9:00
add a comment |
It works. Unfortunately, this filter causes the page to become slow to load the results. Hope there has any alternative. Overall, thanks for the option.
– Samudra Ajri Kifli
Mar 11 at 7:27
@SamudraAjriKifli it's because of regular expression
– Davit Tovmasyan
Mar 11 at 9:00
It works. Unfortunately, this filter causes the page to become slow to load the results. Hope there has any alternative. Overall, thanks for the option.
– Samudra Ajri Kifli
Mar 11 at 7:27
It works. Unfortunately, this filter causes the page to become slow to load the results. Hope there has any alternative. Overall, thanks for the option.
– Samudra Ajri Kifli
Mar 11 at 7:27
@SamudraAjriKifli it's because of regular expression
– Davit Tovmasyan
Mar 11 at 9:00
@SamudraAjriKifli it's because of regular expression
– Davit Tovmasyan
Mar 11 at 9:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056652%2fdjango-truncatewords-and-shows-the-searched-word%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown