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;








2















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










share|improve this question




























    2















    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










    share|improve this question
























      2












      2








      2


      1






      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










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 4:17









      Samudra Ajri KifliSamudra Ajri Kifli

      445




      445






















          1 Answer
          1






          active

          oldest

          votes


















          2














          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:



          enter image description here






          share|improve this answer























          • 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











          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
          );



          );













          draft saved

          draft discarded


















          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









          2














          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:



          enter image description here






          share|improve this answer























          • 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















          2














          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:



          enter image description here






          share|improve this answer























          • 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













          2












          2








          2







          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:



          enter image description here






          share|improve this answer













          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:



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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

















          • 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



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved