Sep-26-2020, 02:52 PM
I am currently working on my website, which is a translator which you input a phrase and it gets translated into an invented language.
Here's the code of the translator function:
Here's the code of the translator function:
def translator(phrase): translation = "" for letter in phrase: if letter.lower() in "a": if letter.isupper: translation = translation + "U" else: translation = translation + "u" elif letter.lower() in "t": if letter.isupper: translation = translation + "A" else: translation = translation + "a" elif letter.lower() in "c": if letter.isupper: translation = translation + "G" else: translation = translation + "g" elif letter.lower() in "g": if letter.isupper: translation = translation + "C" else: translation = translation + "c" return translationHowever, I am stuck in showing this funcion in my web, here's the code in views.py:
from .translate import translator def translator_view(request): return render(request,'main/translator.html') def translated_view(request): text = request.GET.get('text') print('text:', text) translate = translator dt = translator.detect(text) tr = translated.text context = { 'translated': tr } return render(request, context, 'main/translated.html')Here's the template where you introduce the text:
<form action="{% url 'translated' %}" method= "get"> <div class="form-group"> <center><h2 class = "display-3">TRANSLATE YOUR DNA CHAIN</h2></center> <br> <br> <textarea class="form-control" id="exampleFormControlTextarea1" rows="6"></textarea> <br> <button type='Submit' class= "btn btn-primary btn-lg btn-block">Translate</button> </div> </form>Here's the template that should would show the translation.
{% extends "base.html"%} {% block content%} <div > <center><h2 class = "display-4">DNA TRANSLATED SUCCESFULLY INTO</h2></center> <br> <br> <br> <h3> {{ translated }} </h3> </div> {% endblock content%}