python - Create cookies when user clicks a button -


i want when person clicks button on page, function in view called creates cookies on user's machine , store cookie id in models.

template(html page):

<form action="#" method="get">         <p style="text-align: center;">              <input type="submit" class="optoutbutton" value="opt-out" name="optoutbutton"> </p>     </form> 

views.py

class useroptout(templateview):     template_name = 'debug/opt-out-child.html'          def user_opt_out(request):         if(request.get.get('optoutbutton')):             response = httpresponse('hahahaha')             response.set_cookie('id', 1)             return response         if request.cookies.has_key( 'id' ):             value = request.cookies[ 'id' ]         return render_to_response(debug/opt-out-child.html) 

but, when click button nothing happens. can me doing wrong?

user_opt_out not method called automatically in templateview. should put in get method instead.

although since explicitly render , return full response method anyway, don't know why you've used class-based view @ all: use normal view function.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -