我希望当一个人在我的页面上单击一个按钮时,视图中的一个函数被调用,它在用户的机器上创建cookie,然后将cookieid存储在我的模型中。你知道吗
模板(HTML页):
<form action="#" method="get">
<p style="text-align: center;">
<input type="submit" class="optOutButton" value="Opt-Out" name="optOutButton"> </p>
</form>
你知道吗视图.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)
但是,当我点击按钮时什么也没发生。有人能帮我做错事吗?你知道吗
user_opt_out
不是在TemplateView中自动调用的方法。您可能应该将其放在get
方法中。你知道吗尽管既然显式呈现并返回方法的完整响应,我还是不知道为什么使用基于类的视图:只使用普通的视图函数。你知道吗
相关问题 更多 >
编程相关推荐