title: how to display a specific searched word from a string in django?
body: <p>I have developed the searched feature in Django using <code>Q</code> object, and get the result like this: <strong>what recommendations are you looking for?</strong></p>
  <p>I searched using word recommendations and it displayed the whole object of the model.</p>
  <p>I am using this query for search feature in <code>views.py</code>:</p>
  <pre><code>recommendations_searched_query = Report.objects.filter(Q(recommendations__icontains=query))
  </code></pre>
  <p>and template tags in <code>html</code></p>
  <pre><code>{{recommendations.recommendations|truncatewords:5}}
  </code></pre>
  <p>What I want is:
  when I type word recommendations in the search field,
  the query should display the word recommendation from the string and 5 words before and 5 words after the searched word.</p>
  <p>you can guide me using this string:</p>
  <pre><code>I want to test the search queries for recommendations in the Reports model
  </code></pre>
  <p><strong>EDIT</strong>
  I have successfully got a specific word from the string by using this following logic:</p>
  <pre><code>recommendations_searched_query = Report.objects.filter(Q(recommendations__icontains=query))
          result = [q for q in recommendations_searched_query]
          recommended_query = []
          for r in result:
              rec = r.recommendations.split()
              if query in rec:
                  recommended_query.append(query)
                  break
  </code></pre>
  <p>Now want to get the next 5 or last 5 words from the string.</p>