Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在djangocms插件中集成django应用程序表单_Django_Django Forms_Django Templates_Django Cms - Fatal编程技术网

如何在djangocms插件中集成django应用程序表单

如何在djangocms插件中集成django应用程序表单,django,django-forms,django-templates,django-cms,Django,Django Forms,Django Templates,Django Cms,我编写了一个简单的django应用程序,用于在用户填写表单时存储电子邮件地址。一切都很好,但当我按照这个步骤将我的应用程序集成到django cms中时,我注意到我的表单并没有像我移动到django cms之前那样显示在插件中。似乎{%csrf\u token%}和{{form.as\u p}}在插件中不起作用。 有人知道为什么吗 这是我的cms_plugin.py from cms.plugin_base import CMSPluginBase from cms.plugin_pool im

我编写了一个简单的django应用程序,用于在用户填写表单时存储电子邮件地址。一切都很好,但当我按照这个步骤将我的应用程序集成到django cms中时,我注意到我的表单并没有像我移动到django cms之前那样显示在插件中。似乎
{%csrf\u token%}
{{form.as\u 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)

和forms.py(也是主应用程序)


哪一个文件可能是错误的,或者我在哪里可以找到一个有用的帖子或其他东西。我在这里找到的唯一的东西是。但这对我不起作用。我很乐意得到一个好的小费

关于如何将表单集成到插件的非常好的示例:

这里有一个非常好的视频教程:


您能否描述一下显示插件时会发生什么情况?另外,还有一些其他问题,你是否创建了任何可以工作的插件?Python/Django/Django CMS的哪个版本?你能分享你的模板标记吗?在处理表单时,有一件事会让新的CMSPlugin用户感到困惑,您需要了解,插件中的表单通常不能发布到自身,因为它没有唯一的URL,而且单个插件可能会在同一页面上多次出现,因此,发布通常很复杂。但是,使用AJAX发布效果很好,正如@m15hbah在下面发布的链接中所指出的那样。我的表单的well{%csrf_token%}{{form.as_p}不显示提交按钮。是的,我以前还设计了另外两个应用程序来使用django cms,但是表单没有问题,因为它们只是在django admin中。现在,我需要他们可以为我的网站的访问者。我使用了Django1.7、python2.7和DjangoCMS3.0。Atm我正在关注m15hbah的链接,但需要一点。谢谢你的回答:你找到了吗,如何在模板中获得一个表单
{{{form.as_p}}
来正确呈现?我想渲染上下文需要为此提供一些信息。mishbah的答案指向Djangoms表格。正如我所理解的,它不是为第三方应用程序编写插件。
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
from django import forms
from .models import Recipient

class NewsletterForm(forms.ModelForm):

    class Meta:
        model = Recipient
        fields = ('adress','name', 'lastname',)