I am currently working on my first website and I'm working with class-based views because I've been told their inheritance is outstanding.
Here's the code so you can make yourselves an idea of what I'm trying to do before I tell you the error I'm having.
class TranslatorView(View):
def translate_amino(self, codon):
return self.amino_mapper.get(codon, "")
def build_protein(self, phrase):
protein = []
i = 0
while i < len(phrase):
codon = phrase[i: i + 3]
amino = self.translate_amino(codon)
if amino:
protein.append(amino)
else:
print(f"The codon {codon} is not in self.mapper_1")
i += 3
return protein
def error_1(self, request):
amino_1= self.build_protein(request.GET.get('phrase',''))
if len(amino_1) % 3:
messages.error(request, "DNA chain must be divisible by 3")
return redirect('/')
Basically, what I'm trying to do is to inherit the function build_protein to the def error_1. That's why I create a variable called amino_1 equal to the def build_protein. Afterwards, I create a condition saying if amino_1 detects a phrase that it's a total number of letters aren't divisible by three, it should raise a value error. However, it appears it's not inheriting anything at all.