使用 Django 1.5.5、Django-CMS 2.4.2 我为 django-cms *(cms.plugin_base.CMSPluginBase)* 编写了一个插件。插件创建某种形式,效果很好。但是我遇到了一个问题 - 提交表单后 - 我该如何设置cookie?
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from poll.models import PagePoll
from poll.forms import PollForm
from django.http import HttpResponse
class PollPlugin(CMSPluginBase):
""" upload a poll """
model = PagePoll
name = u'Poll'
render_template = u"plugins/page_poll.html"
def render(self, context, instance, placeholder):
#upload poll form
request = context['request']
form = PollForm(instance.poll, request.POST)
#validate the form
if request.method == 'POST':
if form.is_valid():
form.save()
#=SAVE COOKIES HERE=
else:
form = PollForm(instance.poll)
context['form'] = form
return context
plugin_pool.register_plugin(PollPlugin)