title: Form input to a template
body: <h2>EXPECTED OUTPUT</h2>
  
  <p>Assuming that the user enters "anaconda" in the <code>Form</code>:</p>
  
  <pre><code>Hashtag Search Results
  
  You searched for: anaconda
  </code></pre>
  
  <h2>ACTUAL OUTPUT</h2>
  
  <pre><code>Hashtag Search Results
  
      1) You searched for: &lt;QuerySet [&lt;Hashtag: &gt;, &lt;Hashtag: anaconda&gt;]&gt;
  </code></pre>
  
  <h2>CODE</h2>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>from django.db import models
  
  
  class Location(models.Model):
      """ Model representing a Location, attached to Hashtag objects through a
      M2M relationship """
  
      name = models.CharField(max_length=1400)
  
      def __str__(self):
          return self.name
  
  class Hashtag(models.Model):
      """ Model representing a specific Hashtag serch by user """ 
  
      search_text = models.CharField(max_length=140, primary_key=True)
      locations = models.ManyToManyField(Location, blank=True)
  
      def __str__(self):
          """ String for representing the Model object (search_text) """
          return self.search_text
  
      def display_locations(self):
          """ Creates a list of the locations """
          # Return a list of location names attached to the Hashtag model
          return self.locations.values_list('name', flat=True).all()
  </code></pre>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>from django import forms
  from django.forms import ModelForm
  from django.utils.translation import ugettext_lazy as _
  
  from .models import Location, Hashtag
  
  
  class SearchHashtagForm(ModelForm):
      """ ModelForm for user to search by hashtag """
  
      def clean_hashtag(self):
          data = self.cleaned_data['search_text']
          # Check search_query doesn't include '#'. If so, remove it.
          if data[0] == '#':
              data = data[1:]
          # return the cleaned data
          return data
  
      class Meta:
          model = Hashtag
          fields = ['search_text',]
          labels = {'search_text':_('Hashtag Search'), }
          help_texts = { 'search_text': _('Enter a hashtag to search.'), }
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>from django.http import HttpResponse, HttpResponseRedirect
  from django.shortcuts import get_object_or_404, render
  from django.urls import reverse
  from django.views import generic
  
  from .models import Location, Hashtag
  from .forms import SearchHashtagForm
  
  
  def hashtag_search_index(request):
      """ View function for user to enter search query """
  
      # If POST, process Form data
      if request.method == 'POST':
          # Create a form instance and populate it with data from request (binding):
          form = SearchHashtagForm(request.POST)
          # Check if form is valid
          if form.is_valid():
              search_text = form.cleaned_data['search_text']
              form.save()
              # redirect to a new URL
              return HttpResponseRedirect(reverse('mapping_twitter:results'))
  
      # If GET (or any other method), create the default form
      else:
          form = SearchHashtagForm()
  
  context = {'form':form, 'search_text':Hashtag.search_text}
  return render(request, 'mapping_twitter/hashtag_search_index.html', context)
  
  
  class SearchResultsView(generic.ListView):
      """ Generic class-based view listing search results of locations """
      model = Hashtag
      template_name = 'mapping_twitter/results.html'
  
      def get_queryset(self, **kwargs):
          qs = super(SearchResultsView, self).get_queryset()
          return qs
  
      def get_context_data(self, **kwargs):
          context = super(SearchResultsView, self).get_context_data(**kwargs)
          context['search_text'] = Hashtag.objects.all()
          return context
  </code></pre>
  
  <p><strong>results.html</strong></p>
  
  <pre><code>&lt;h1&gt;Hashtag Search Results&lt;/h1&gt;
  
  &lt;p&gt;1) You searched for: {{ search_text }}&lt;/p&gt;
  
  {% for obj in queryset %}
      &lt;p&gt;2) You searched for: {{ obj.search_text }}&lt;/p&gt;
  {% endfor %}
  </code></pre>