Я нуб в Flask и Python. Это мой frstfsfs fsf fsfsfs
Моя цель - создать веб-приложение. В моем приложении 3 файла. В браузере есть 3 поля:
The sine2 of ------------ equals
The cossine2 of ------------ equals
sin2(x) + co2(x)------------ equals
Работает только поле sine2, показывающее значение. Больше ничего не работает.
Цель:
Enter a value in sine2 and click on the equal. The result of sine2 is showed.
The value appears in the field cosine2 and sin2+cos2. After the cliking on equal the cossine2 is showed.
Then click on the square sine to show the value.
The same applies when the cosine value is entered first.
визуализация в браузере
controller.py:
from flask import Flask, render_template, request
from compute import *
from model import InputForm
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
form = InputForm(request.form)
if request.method == 'POST' and form.validate():
r = form.r.data
s = sin2(r)
else:
s = None
return render_template("view.html", form=form, s=s)
if request.method == 'POST' and form.validate():
d = form.r.data
e = cos2(d)
else:
e = None
return render_template("view.html", form=form, e=e)
if request.method == 'POST' and form.validate():
f = form.r.data
h = sin2cos2(f)
else:
h = None
return render_template("view.html", form=form, h=h)
if __name__ == '__main__':
app.run(debug=True)
compute.py
import math
def sin2(r):
return (math.sin(r)) ** 2
def cos2(r):
return (math.cos(r)) ** 2
def sin2cos2(r):
return (math.sin(r)) ** 2 + (math.cos(r)) ** 2
/ template / view. html
<form method=post action="">
The sine2 of
{{ (form.r) }}
<input type=submit value=equals>
{% if s != None %}
{{ s }}
{% endif %}
<div>
The cossine2 of
{{ (form.r) }}
<input type=submit value=equals>
{% if e!= None %}
{{ e }}
{% endif %}
</div>
<div>
sin2(x)+cos2(x)
{{ (form.r) }}
<input type=submit value=equals>
{% if h!= None %}
{{ h }}
{% endif %}
</div>
</form>