Django-cms Placeholderfield 不工作,抛出 lambda 异常
Posted
技术标签:
【中文标题】Django-cms Placeholderfield 不工作,抛出 lambda 异常【英文标题】:Django-cms Placeholderfield not working, throws lambda exception 【发布时间】:2013-06-04 21:03:09 【问题描述】:我在 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)
版本
我正在使用
Django-cms: 2.2
Django: 1.5.1
Linux: 12.04 LTS
我想知道如何在占位符字段中放置一个插件,而不会出现那个烦人的错误。提前致谢
【问题讨论】:
【参考方案1】:ItemPlugin 需要拥有 PlaceholderAdmin 的魔力。试试这个:
from cms.admin.placeholderadmin import PlaceholderAdmin
...
class ItemPlugin(CMSPluginBase, PlaceholderAdmin):
...
【讨论】:
帮我修好了,谢谢!为什么文档中没有那个...?【参考方案2】: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
【讨论】:
以上是关于Django-cms Placeholderfield 不工作,抛出 lambda 异常的主要内容,如果未能解决你的问题,请参考以下文章