"render_placeholder"没有出现在djangoCMS模板中 [英] "render_placeholder" not showing up in djangoCMS template

查看:111
本文介绍了"render_placeholder"没有出现在djangoCMS模板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照以下网站上的说明进行操作,以便从模型中渲染占位符字段,但我没有进行管理.

I have followed the instructions on the following site in order to render a placeholder field from a model, but I didn't manage.

http://docs.django-cms .org/en/release-3.4.x/how_to/placeholders.html

这是我的模特.

from django.db import models
import uuid
from django.utils import timezone
from cms.models.fields import PlaceholderField

class HomePage(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True)
    my_placeholder = PlaceholderField('placeholder_name')
    modified_date = models.DateTimeField(default=timezone.now)

    class Meta:
       db_table = "home_page_content"
       verbose_name = 'Home Page Content'
       verbose_name_plural = 'Home Page Content'

这是我的观点.

from django.shortcuts import render
from app.models.home_page import HomePage

def HomePageContent(request):

   object = HomePage.objects.all()
   return render(request, 'home.html', {'object': object})

这就是我在模板中呈现占位符的方式.

This is how I render the placeholder in the template.

    {% load cms_tags %}

    {% for obj in object %}
      {% render_placeholder obj.my_placeholder "640" %}
    {% endfor %}

什么也没出现.

我想念什么?任何帮助将不胜感激!

What am I missing? Any help would be much appreciated!

推荐答案

我认为您在管理员上缺少PlaceholderAdminMixin.您没有指定管理员,所以我不确定.

You are missing the PlaceholderAdminMixin on the admin I think. You did not specify the admin so I am not sure.

from django.contrib import admin
from cms.admin.placeholderadmin import PlaceholderAdminMixin

class HomePageAdmin(PlaceholderAdminMixin, admin.ModelAdmin):
    pass

这篇关于"render_placeholder"没有出现在djangoCMS模板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆