模板文件(Python / Bottle)中的运行函数

时间:2018-12-04 00:50:10

标签: python html python-3.x flask bottle

我正在使用Bottle创建各种简单的退休计算器,但是我在处理python模板文件的模板时遇到了麻烦。例如,我有此代码

<%
import statistics, numpy

medianStockReturn = []

def stockReturn():
    global medianStockReturn
    yearStockReturn = numpy.random.normal(11.4, 19.7, 1000)
    yearMedianStockReturn = statistics.median(yearStockReturn)
    yearMedianStockReturn = yearMedianStockReturn / 100 + 1
    medianStockReturn.append(yearMedianStockReturn)
stockReturn()
end
%>

<!DOCTYPE html>
<html lang = "en-us">
    <head>
        <title>Retirement Calculator</title>
        <meta charset = "utf-8">
        <link rel="stylesheet" type="text/css" href="../static/retirementStyle.css">
   </head>
   <body>
       <h2> this is a test; your stock return is {{medianStockReturn}}</h2>
   </body>
</html>

但是,此代码的输出为:“这是一个测试;您的股票收益为[]”

按照编写的方法,该函数应在中位数股票返回值后面附加一个生成的值,但是没有,我不确定为什么。

1 个答案:

答案 0 :(得分:0)

您需要将 string prefabPath = "Assets/demo1/Resources/GameObject.prefab"; Object prefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath); 移到end以上函数定义结束之后的位置

stockReturn()