You have a lot of ways to achieve what you want. I would recommend using localStorage of user browser (docs) to save that class:
localStorage.setItem('buttonClass', 'some-class');
And then later when you refresh the page just check that if localStorage has buttonClass key set.
const savedClass = localStorage.getItem('buttonClass');
if (savedClass) {
// automatically add to your button
} else {
// behave as usual
}
If you think that it is not permanent enough you can use Django session to store that value. This is better than storing it on some other table but much worse than using JavaScript along with local storage:
def your_view(request):
button_class = request.session.get('saved_button_class')
context = {
'saved_button_class': button_class
}
render(request, 'templates/index.html', context=context)
In your template check for saved_button_class variable.
And you must implement new view that will accept AJAX request, telling that user have clicked that button.
from django.http import JsonResponse
def ajax_view(request):
request.session['saved_button_class'] = 'button_class'
return JsonResponse({'saved': True})
Then on page refresh, you will have saved_button_class on user's session already