Flask 测验用烧瓶计时器

Flask 测验用烧瓶计时器,flask,timer,Flask,Timer,这里是我在main.py中的一些代码: @app.route('/dashboard', methods = ['GET', 'POST']) def dashboard(): global username return render_template('dashboard.html', username = username) @app.route('/quiz', methods = ['GET', 'POST']) def quiz(): print('cont

这里是我在main.py中的一些代码:

@app.route('/dashboard', methods = ['GET', 'POST'])
def dashboard():
    global username
    return render_template('dashboard.html', username = username)

@app.route('/quiz', methods = ['GET', 'POST'])
def quiz():
    print('contest')

    global problems
    global answers
    global username
    print(db[username])
    print(request.form)
    


    if db[username][1] == False:
        return render_template('quiz.html', problems = problems, qname = None, submitted = db[username][1], username = username)

    elif request.method == 'GET' and db[username][1] == False and db[username][2] == False:
        print('Hello')
        req = request.form
        score = 0
        for i in range(len(answers)):
            if str(req.get('Q' + str(i))) == answers[i]:
                score = score + 1 
        u = [db[username][0], True, score]
        db[username] = u
        print('Just completed')
        return render_template('finished.html', score = score)

    elif request.method == 'GET' and db[username][1]:
        print(db[username][1])
        print("Prev Completed")
        return render_template('finished.html', score = db[username][2])
下面是我在dashboard.html中的代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QUIZ</title>
  <link rel = "icon" href = "static/images/logo.png" type = "image/x-icon">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">

</head>
<body>
  <div class="banner">
            <div class="navbar">
        <a href="/"><img src="static/images/logo.png" class="logo"></a>
        </div>
    <div class="content">
      <h2>Dashboard  -  {{username}}</h2>
    <center>
    <a href="/quiz"><button href="/quiz" class="button"><img src="static/images/logo.png" width="50" height="50"><h1>Quiz</h1></button></a>
    <form action="/" method="post">
    <input type="submit" value="Sign out"/>
    </form>
  </center>
  </div>
  </div>
</body>
</html>

测验
仪表板-{{username}
下面是我在quick.html中的代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QUIZ</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/quiz.css') }}">



</head>
<body>
  <div class="banner">
    <div class="content">
    {% if submmitted %}
    <div>You have already submitted your test.</div>
    {% else %}
    <form action="/quiz">
    <input readonly type="text" name="uname" id="uname" value = "{{username}}">
    {% for i in range(3) %}
    <div class="card">
      <h2>{{i+1}}</h2>
    <p>{{problems[i]}}</p>
    {% set qname = "Q" + i|string %}
    <input type="text" name="{{qname}}" id="{{qname}}">
    </div>
    {% endfor %}
    <p></p>
    <input type="submit" value="Submit" onclick="submitted()"/>
    </form>
    {% endif %}




    <script>

function submitted () {
        // submits the responses in a file
};   
    </script>
    </div>
</div>
</body>
</html>

测验
{%if submmitted%}
您已经提交了测试。
{%else%}
{范围(3)%内的i的百分比}
{{i+1}}
{{问题[i]}

{%set qname=“Q”+i | string%} {%endfor%}

{%endif%} 函数已提交(){ //在文件中提交响应 };
现在,我想添加一个计时器,用于在仪表板上显示测验,其中测验只能在特定的时间限制之间访问(无论时区如何,每个人都应该在同一时间访问)

我还想添加另一个计时器,因此在开始测验时,用户只能在特定时间访问测验,一旦时间结束,测验结束

我希望我能得到一些帮助

如果感觉这是一个漫长的过程,我可以在Discord上进行协作,或者在replit上编辑代码

提前谢谢