D
D
Djigo2019-07-15 11:34:34
Django
Djigo, 2019-07-15 11:34:34

python and django and html help, How to set a timer so that a button disappears for 24 hours when clicked?

VIEWS.PY:

def fishspeed_bonus(request):
    if request.GET.get('button') == 'button':
        a = 1
    else:
        a = 0
    return render(request, 'fishspeed/bonus.html',{
    'a': a,
    })

HTML:
{% if a == 0 %}
        <button type="submit" class="btn btn-blue btn-righ" name="button" value="button">GET BONUS</button>
      {% endif %}
      {% if a == 1 %}
        <b class="my">Next bonus after 24 hours</b>
      {% endif %}
    </center>

It is necessary that a person presses a button and he disappears for 24 hours from server time

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FulTupFul, 2019-07-15
@Djigo

import datetime


def fishspeed_bonus(request):
    now = datetime.datetime.now()
    bonus_time = request.session.get("bonus_time")
    if bonus_time:
        delta = now - datetime.datetime.fromisoformat(bonus_time)
        if delta.days > 0:
            bonus = True
        else:
            bonus = False
    else:
        request.session['bonus_time'] = datetime.datetime.now().isoformat()
        bonus = True
    return render(request, 'fishspeed/bonus.html', {"bonus": bonus})

{% if bonus %}
        <button type="submit" class="btn btn-blue btn-righ" name="button" value="button">GET BONUS</button>
{% else %}
        <b class="my">Next bonus after 24 hours</b>
      {% endif %}
    </center>

A
alternativshik, 2019-07-15
@alternativshik

We write the date somewhere in the database and then check whether to draw the button or not...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question