我在django-cms上写了一个自定义插件并添加了一个占位符字段。一旦在占位符上添加了该插件,我尝试在占位符字段中使用前端编辑插件添加它并抛出:
关于前端编辑
Failed to load resource: the server responded with a status of 404 (NOT FOUND)
http://localhost:8000/es/admin/cms/page/add-plugin/
在控制台上显示
"POST /es/admin/cms/page/add-plugin/ HTTP/1.1" 404 1620
当我尝试使用管理界面或前端编辑
编辑放置在页面中的自定义插件时TypeError at /es/admin/cms/page/4/edit-plugin/14/
<lambda>() takes exactly 1 argument (2 given)
Request Method: GET
Request URL: http://localhost:8000/es/admin/cms/page/4/edit-plugin/14/
Django Version: 1.5.1
Exception Type: TypeError
Exception Value:
<lambda>() takes exactly 1 argument (2 given)
Exception Location: /home/ed/Envs/django/local/lib/python2.7/site-packages/cms/forms/widgets.py in render, line 201
Python Executable: /home/ed/Envs/django/mh/../bin/python
我的插件代码如下所示
Models.py
from cms.models.pluginmodel import CMSPlugin
from cms.models.fields import PlaceholderField
from django.db import models
# Create your models here.
class Item(CMSPlugin):
title = models.CharField(max_length=100, default="Item Name",verbose_name=u'Titulo')
description = PlaceholderField('Item_Description')
image = models.ImageField(upload_to="uploads/images/",verbose_name=u'Imagen')
imageDescription = models.CharField(max_length=50,default="Image",verbose_name=u'Descripcion de la imagen')
admin.py
from django.contrib import admin
from cms.admin.placeholderadmin import PlaceholderAdmin
from projects.models import Item
admin.site.register(Item, PlaceholderAdmin)
cms_plugins.py
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from cms.models.pluginmodel import CMSPlugin
from django.utils.translation import ugettext_lazy as _
from models import Item
class ItemPlugin(CMSPluginBase):
model = Item
name = "Item Plugin"
render_template = "item_plugin.html"
def render(self, context, instance, placeholder):
context['instance'] = instance
return context
#Registers the plugin
plugin_pool.register_plugin(ItemPlugin)
VERSIONS
我正在使用
Django-cms: 2.2
Django: 1.5.1
Linux: 12.04 LTS
请问我想知道如何在占位符字段内放置一个插件,然后输出那个恼人的错误。提前致谢
答案 0 :(得分:0)
django CMS 2.2不支持Django 1.5 [1]。
如果您需要Django 1.5,请升级到最新的2.4版本。
[1] http://docs.django-cms.org/en/2.2/getting_started/installation.html#requirements
答案 1 :(得分:0)
ItemPlugin需要拥有PlaceholderAdmin的魔力。试试这个:
from cms.admin.placeholderadmin import PlaceholderAdmin
...
class ItemPlugin(CMSPluginBase, PlaceholderAdmin):
...