我编写了一个简单的django应用程序,用于在用户填写表单时存储电子邮件地址。一切正常,但当我按照这个tutorial将我的应用程序集成到django-cms中时,我注意到我的表单在插件中显示不像我将它移到django-cms之前那样。看起来{% csrf_token %}和{{ form.as_p }}在插件中不能工作。有人知道为什么吗?
这是我的cms_plugin.py
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from newsletter_djangocms.models import NewsletterPlugin
from django.utils.translation import ugettext as _
class CMSNewsletterPlugin(CMSPluginBase):
model = NewsletterPlugin
module = _("Recipients")
name = _("Newsletter Plugin")
render_template = "newsletter_djangocms/add.html"
def render(self, context, instance, placeholder):
context.update({'instance': instance})
return context
plugin_pool.register_plugin(CMSNewsletterPlugin) 主应用程序的models.py (非CMSPlugin)
from django.db import models
class Recipient(models.Model):
adress = models.EmailField(max_length=100)
name = models.CharField(max_length=100)
lastname = models.CharField(max_length=100)
def __str__(self):
return self.adress和forms.py (也是主应用程序)
from django import forms
from .models import Recipient
class NewsletterForm(forms.ModelForm):
class Meta:
model = Recipient
fields = ('adress','name', 'lastname',)在哪个文件中可能是错误的,或者我在哪里可以找到帮助完整的帖子或其他什么。我在这里找到的唯一的东西是this。但这对我不起作用。如果有一个好的小费,我会很高兴的。
发布于 2015-02-20 04:15:26
https://stackoverflow.com/questions/28612789
复制相似问题