Jason Howard
Jason Howard

Reputation: 1586

Setting session variable on click

I've got a popup message with a close button at the top. If the user clicks the close button, they should never see the message again while on the site. If they don't click the close button, they will see it on the top of each page on the site.

When the user clicks the close button, I want to set request.session['promo'] to 0. On subsequent page loads on the site, if request.session['promo'] == 0, I will not show the popup message.

What is the best way of setting a session variable on click in django?

Thanks for the direction!

Upvotes: 2

Views: 1308

Answers (1)

pohankargaurang
pohankargaurang

Reputation: 43

In HTML OnClick of button just call a function in views.py
Ex: IN HTML :<Button onclick={% your_fucntion %}></button>

IN VIEWS.PY :

def your_fucntion(request):
                  request.session['promo'] == 'your_variable' 

for getting variable :

promo = request.session['promo'] 

Upvotes: 1

Related Questions