when a user signs up, they get redirected to the homepage. If it is their first time logging in, I want to display a div, however if it is not their first time, I do not want this div to appear. Currently, I am relying on date_joined
andlast_login
to do this check.
However this only checks dates and not the time. Therefore the div will still appear until the date has changed. I only want the div displayed once. This is when the user first logs in.
Here is my code so far: views.py:
def home(request):
context={}
user = request.user
if user.last_login.date() == user.date_joined.date():
context['isFirstTime'] = 'isFirstTime'
else:
pass
return render(request, 'home.html', context)
template:
{% if isFirstTime %}
<div style="width: 300px; height: 300px; background-color: green;">
</div>
{% endif %}
Does anybody know how I can alter this so it works with the current time and not the current date. This way the div is only displayed when a user first logs in. Anybody know a solution? Thank you. Also date_joined
and last_login
are datetime objects stored in the database.