Как передать результаты функции в HTML, используя Flask - PullRequest
0 голосов
/ 05 марта 2020

У меня есть функция main (), которая запускает другие функции внутри. Мои окончательные результаты отображаются в "subtractboth ()". Как я могу отобразить subtractboth () на странице HTML, которую отображает скрипт flask?

Я пытался вызвать {{main}} внутри моего файла html, но это не дало никаких результатов.

test_index. html

<doctype html="">
<html>
<head>
</head>
<body>
<h1>Summary Billing Allocation Search</h1>

<table cellspacing="0" cellpadding="2" style="border-spacing: 0;
text-rendering: optimizeLegibility; border-collapse: collapse; border: 3px solid white;">
<font face="calibri" style="font-weight: bold; font-size: 20">
<tr bgcolor="#0097da" style="font-weight: bold; border-bottom: 1px solid white; color:white">
<th colspan = '5' align='center' style="padding: 2px 5px 2px 5px;">Summary Bill Allocation 
Results</th>
</tr>
</font>
<font face="calibri" style="font-weight: bold; font-size: 18">
<tr bgcolor="#78c239" style="font-weight: bold; border-bottom: 1px solid white; padding-left: 5px;
 padding-right:5px; color:white">
    <th style="border-right: 2px solid white">Cash Date</th>
    <th style="border-right: 2px solid white">Name</th>
    <th style="border-right: 2px solid white">Master</th>
    <th style="border-right: 2px solid white">Subordinate</th>
    <th style="border-right: 2px solid white">Debit Amount</th>
</tr>
</font>
{{a}}
</table>
</body>
</html>

library.py

@app.route('/results', methods=['GET', 'POST'])
def main():
    connect()
    masteracct = request.args.get('masteracct')
    cashdt = request.args.get('cashdt')
    billdt = request.args.get('billdt')
    allocation(connect(), cashdt, masteracct)
    statement(connect(), billdt, masteracct)
    a = subtractboth(statement(connect(),billdt, masteracct), allocation(connect(),cashdt, 
    masteracct))
    print(a)
    html = render_template('test_results.html')
    return html

1 Ответ

3 голосов
/ 05 марта 2020

Часть основного метода, в которой вы фактически визуализируете шаблон, вы должны передать значение a, которое можно использовать в html коде.

Предлагаемое изменение:

return render_template('test_results.html', a=a)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...