Answer the question
In order to leave comments, you need to log in
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,
})
{% 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>
Answer the question
In order to leave comments, you need to log in
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>
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 questionAsk a Question
731 491 924 answers to any question