![](/img/trans.png)
[英]Python-Flask - How to access sqlite database.db on pythonanywhere.com without specifying its directory?
[英]Automatically reload Python-Flask application hosted on PythonAnywhere.com
我需要每天重新加載我在pythonAnywhere上托管的燒瓶應用程序。 是否可以使用我已有的代碼自動重新加載應用程序?
該應用程序是一個簡單的日程表:
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)
我已經完成了: 這個鏈接到pythonAnywhere論壇,但是我必須在我的電腦上而不是在應用程序本身上部署的腳本。
問題:如何每天自動重新加載應用程序? 有沒有辦法在網站上使用日程安排功能?
只是想指出你也可以稍微改變你的代碼,你根本不需要完成所有這些重新加載。
只需在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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.