title: add_message() argument must be an HttpRequest object, not 'str'
body: <p>I am currently working on a django website which translates a dna chain into a protein. Basically, you input a group of letters divisible by three and then it gets translated into a protein. This part of the code works perfectly. However, I am experiencing some troubles with the messages. If you want to see the documentation of django messages, here it is: <a href="https://docs.djangoproject.com/en/3.1/ref/contrib/messages/" rel="nofollow noreferrer">https://docs.djangoproject.com/en/3.1/ref/contrib/messages/</a>.</p>
  <p>What I want to do is: when you input a group of letters which isn't divisible by three, it should raise a message with the level or error (message.error). Here's the code:</p>
  <pre><code>class TranslatorView(View):
      def translate_amino(self, codon):
          return self.amino_mapper.get(codon, &quot;&quot;)
  
  
     
  
      def build_protein(self, request, phrase):
          protein = []
          i = 0
          while i &lt; len(phrase):
              codon = phrase[i: i + 3]
              amino = self.translate_amino(codon)
              if amino:
                  protein.append(amino)
              else:
                  print(f&quot;The codon {codon} is not in self.mapper_1&quot;)
              i += 3
          if len(phrase) % 3:
              messages.error(request, 'DNA CHAIN INVALID')
          else:
              return protein
      
  
  
      
  
      def get(self, request, *args, **kwargs):
          return render(request, 'main/translator.html')
  
      def post(self, request, *args, **kwargs):
          phrase = request.POST.get('text', 'translation')
          protein = request.POST.get('text','protein')
          return render(request, self.template_name, {'translation': self.translate(phrase), 'protein': &quot;, &quot;.join(self.build_protein(protein, phrase))})
  
      
  </code></pre>
  <p>However, when I run the code, this error gets raised:</p>
  <p>add_message() argument must be an HttpRequest object, not 'str'.</p>
  <pre><code>        return render(request, self.template_name, {'translation': self.translate(phrase), 'protein': &quot;, &quot;.join(self.build_protein(protein, phrase))}) …
  ▶ Local vars
  C:\Users\marcv\OneDrive\Escriptori\Translate\Scripts\src\translator\views.py, line 176, in build_protein
              messages.error(request, 'DNA CHAIN INVALID') 
  </code></pre>
  <p>I believe this comes from the if statement where i type the message.error.</p>
  <p>However, I don't know how to solve it.</p>
  <p>PS: If you need the calling methods, don't hesitate in telling me</p>