自动重新加载 PythonAnywhere.com 上托管的 Python-Flask 应用程序

Moi*_*was 2 python reload flask pythonanywhere

我需要每天重新加载托管在pythonAnywhere上的 Flask 应用程序。是否可以使用我已有的代码自动重新加载应用程序?

该应用程序是一个简单的天数计数器:

import datetime
from flask import Flask, render_template

app = Flask(__name__)
wsgi_app = app.wsgi_app

currentDate = datetime.date.today()
userInput = '07/22/2015'
targetdate = datetime.datetime.strptime(userInput, '%m/%d/%Y').date()
calc = targetdate - currentDate
msg=str(calc.days)

@app.route('/', methods=['GET','POST'])
def index():
    return render_template('index.html', message=msg)
Run Code Online (Sandbox Code Playgroud)

我已经浏览过: 此链接到 pythonAnywhere 论坛,但它是一个我必须部署在我的电脑上而不是应用程序本身上的脚本。

问:如何每天自动重新加载应用程序?有什么方法可以使用网站上的计划功能来执行相同的操作吗?

con*_*rad 5

只是想指出,您也可以稍微更改代码,并且根本不需要执行所有这些重新加载。

只需在您的函数中进行计算index,每次您再次访问该页面时,就会重新计算天数。

import datetime
from flask import Flask, render_template

app = Flask(__name__)
wsgi_app = app.wsgi_app

userInput = '07/22/2015'
targetdate = datetime.datetime.strptime(userInput, '%m/%d/%Y').date()

@app.route('/', methods=['GET','POST'])
def index():
    currentDate = datetime.date.today()
    calc = targetdate - currentDate
    msg=str(calc.days)
    return render_template('index.html', message=msg)
Run Code Online (Sandbox Code Playgroud)