使用 Django 构建通用的基于块的 CMS
一位设计师最近给了我一份我正在为客户构建的网站的设计方案。它们是很棒的设计,但我真的很摸不着头脑,不知道如何在网站上实现它。
内容可以很容易地分解为数据块或数据块,我可以在其中分配一个用于文本输入的文本区域、几个用于链接按钮的字符字段等,然后将它们依次呈现到页面上。
问题(例如,为什么我不只是引入 Django-CMS 等)是这些块彼此之间非常独特。我可能会为每种块类型构建 20 个不同的模型。我不想绕过预制 CMS,而是想构建一个 Page 模型,然后拥有一个链接到我的抽象 Block 类的有序子类列表的 M2M。我希望我不会失去你。
我不明白我怎么能做到这一点。这些问题浮现在我的脑海中:
是否有一个简单的 CMS 可以完成所有这一切?我是在浪费时间去弄清楚物理原理吗?
从技术上讲,我的块子类将是不同的类型。我是否需要 M2M-through 类的泛型才能链接到它们?是这样,我该怎么做?
如何在内联管理上下文中呈现 x 种不同的表单? (我想要一个带有下面的块列表的页面表单)
用户如何在内联控件中指定块的类型?
编辑:或者,基于模板标签的 CMS 怎么样?
我正在考虑在我的模板中添加这样的内容:
{% editable 'unique_id' 'content-type' %}
另一个例子:
{% editable 'home-intro' 'text' %}
然后我可以将它们粘贴在我想要可编辑的模板周围,以我希望它们可编辑的方式,并且在登录时客户端会看到“编辑文本”、“编辑链接”、“编辑图像”链接只是在右侧字段中弹出。
这将使事情更加锁定,但布局需要保持固定(并且客户端对 HTML/CSS 一无所知),因此在我看来,这是这些方法中的一种或另一种。
A designer recently handed me designs for a site I'm building for a client. They're great designs but I'm really scratching my head as to how I'm going to implement it on the site.
The content can very easily be broken down into blocks or chunks of data where I could allocate a textarea for text input, a couple of charfields for link-buttons, etc and sequentially render them out to the page.
The problem (eg why I'm not just pulling in Django-CMS et al) is the blocks are quite unique from each other. There are perhaps 20 different models that I would build for each block type. Rather than hack around a pre-fab CMS, I'd like to build a Page model and then just have an M2M that links to an ordered list of subclasses of my abstract Block class. I hope I'm not losing you.
I don't understand how I can do this. These questions spring to mind:
Is there a simple CMS that does all of this already? Am I wasting my time trying to figure out the physics?
My Blocks subclasses will technically be different type. Do I need generics for a M2M-through class to link to them? Is so, how do I do that?
How do I render x different forms in an inline admin context? (I'd like to have the page form with a list of the Blocks underneath)
How can the user specify the type of Block in the inline control?
Edit: Or, alternatively, what about a templatetag-based CMS?
I'm thinking of something like plonking this in my template:
{% editable 'unique_id' 'content-type' %}
A further example:
{% editable 'home-intro' 'text' %}
Then I could just stick these around the templates I want to be editable, in the way I want them to be editable and when logged in the client would see "Edit text", "Edit link", "Edit image" links which simply popped up the right field.
This would make things more locked down but the layout needs to remain solid (and the client knows nothing about HTML/CSS) so it's one or other of these methods IMO.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能将您的“块”实现为 Django CMS 插件吗?然后每个页面都是由许多插件构建的。
每个插件都有一个管理表单,可以获取其自身的详细信息,然后页面模板根据您的需要呈现插件。
如果您查看 django-cms 演示的第一页:
https://www. django-cms.org/en/tour-demo/
您将在 (1) 中看到突出显示的插件块 - 在本例中是使用 TinyMCE 或类似工具编辑的格式化文本块。您可以定义自己的插件并将其添加到页面中。
Couldn't you implement your 'Blocks' as Django CMS Plugins? Then each page is just constructed from a number of plugins.
Each plugin has an admin form which gets the specifics for itself, and then the page template renders the plugin as you want it.
If you look at the first page of the django-cms demo:
https://www.django-cms.org/en/tour-demo/
you'll see in (1) a highlighted plugin block - in this case a formatted text block that is edited with TinyMCE or similar. You can define your own plugins and add them to pages.
上个月,我发表了一篇关于如何为 Jinja 构建基本 CMS 的文章(供审阅)。这个模板语言与我之前使用过的 Django 没有太大区别。
你可以在这里找到它。它使用模板继承来填充内容块。
https://codereview.stackexchange。 com/questions/5965/review-request-jinja-cms-for-energiekantoor-nl-on-google-app-engine
或者输入 Google:Jinja CMS
last month I published an article (for review) on how tho build a basic CMS for Jinja. This's templating language does not dffer very much from Django, which I have been using before.
You can find it here. It uses template inheritance to fill the content blocks.
https://codereview.stackexchange.com/questions/5965/review-request-jinja-cms-for-energiekantoor-nl-on-google-app-engine
Or type in Google : Jinja CMS