如何设置一个务与html请求使用烧瓶务?

0

的问题

我想运行html网页在那里我用一个按钮来设置一个特定的时间(见下文),它后来的运行的一个定时任务,通过该模块 烧瓶务. 我如何可以使用 minute, hour, day, month 外面 def get_time() 没有设置的变量的全球?
什么一个坚实的方式使用烧瓶务在这里?

APP = Flask(__name__)
Bootstrap(APP)
crontab = Crontab(APP)

...

@APP.route('/randompage.html' methods = ['POST', 'GET])
def get_time():
    time_req = request.args.get("html_time")
    format_time = datetime.strptime(time_req, "%Y-%m-%dT%H:%M")

    minute = format_time.minute
    hour = format_time.hour
    day = format_time.day
    month = fomrat_time.month

    return render_template('randompage.html', time_req=time_req)


@crontab.job()
def exe_control():
    do something here

按钮在html网页:

<form action="/randompage.html" method="GET">
<input type="datetime-local" name="html_time"/>
<input type="submit"/></form>
cron flask html linux
2021-11-13 12:05:37
1

最好的答案

0

使用价值 minute, hour, day, month 在其他功能,你必须使用 global 变量,或保持在全球 list/dictionary 或者存在 file/数据库和阅读其他的功能。

但如果你想要这些价值观用作值 @crontab.job(minute=..., hour=...) 然后这是无用的。 你应该直接在运行它 get_time 作为正常功能

crontab.job(minute=minute, ...)(exe_control)


APP = Flask(__name__)
Bootstrap(APP)
crontab = Crontab(APP)

# ...

@APP.route('/randompage.html' methods = ['POST', 'GET'])
def get_time():
    time_req = request.args.get("html_time")
    format_time = datetime.strptime(time_req, "%Y-%m-%dT%H:%M")

    minute = format_time.minute
    hour = format_time.hour
    day = format_time.day
    month = fomrat_time.month

    crontab.job(minute=minute, hour=hour, day=day, month=month)(exe_control)

    return render_template('randompage.html', time_req=time_req)

# - without decorator -
def exe_control():
    do something here
2021-11-14 00:00:27

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................