使用 Django 的 CMS 子网站

发布于 2024-08-17 02:13:06 字数 582 浏览 9 评论 0原文

我正在使用 Django 创建一个网站,为各种生产者消费者提供单独的 Web UI。两个 UI(或“子站点”)都有不同的布局、菜单和图形。然而,他们访问相同的数据库和模型,只是从不同的方面(生产者与消费者......)。它全部托管在单个域下,UI 区分是通过 URL 完成的。

当我想将 CMS 集成到该系统中以处理菜单结构和文本内容时,问题就出现了。我应该如何处理不同用户界面的两个不同菜单?我查看了 django-cms 和 django-page-cms,它们似乎只维护一个菜单层次结构。

有什么想法吗?

一种肮脏的解决方案是为 CMS 中的每个 UI 菜单项添加不同的前缀,并修改 CMS 代码,以便它只插入正确 UI 的菜单项(作为 show_menu 模板标记的参数)。

更好的方法是,如果可以拥有 CMS 应用程序的多个实例,以便每个实例都有自己的数据库表。但这对于 django 和例如 django-cms 或 django-page-cms 来说可能吗?

一些进一步的限制:

  • CMS 必须支持本地化
  • 我更喜欢运行单个 Django 实例,以保持配置和测试简单

I'm using Django to create a site that provides a separate web UI for sorts of producers and consumers. Both UIs (or "subsites") have different layouts, menus and graphics. However they access the same database and models, just from different aspects (producer vs. consumer...).It's all hosted under a single domain, the UI differentiation is done with URLs.

The problem comes when I want to integrate a CMS to this system, to take care of the menu structures and textual content. How should I go about handling the two different menus for the different UIs? I took a look at django-cms and django-page-cms, and they seem to maintain only a single menu hierarchy.

Any ideas?

One dirtyish solution would be to add e.g. a different prefix for each UI's menu items in the CMS, and hack the CMS code so that it only inserts the menu items for the correct UI (given as a parameter to the show_menu template tag).

A nicer way would be if it was possible to have multiple instances of the CMS app, so that each of them had their own database tables as well. But is this possible with django and e.g. django-cms or django-page-cms?

Some further restrictions:

  • the CMS must support localization
  • I'd prefer running a single Django instance, to keep the configuration and testing simple

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

○闲身 2024-08-24 02:13:06

我没有使用过 django-cms,所以这只是我的想法。

文档中有一个名为扩展菜单的部分看起来很有希望。不幸的是,他们的大部分配置都在 settings.py 中,因为看起来您可以操纵他们的 CMS_TEMPLATES 来为不同的用户使用不同的基本模板(等)。解决这个问题的一种方法(假设没有更直接的途径)是向 UserProfile 添加一些内容,将用户标识为消费者/生产者。然后在您的 base.html 中执行以下操作:

{% if user.get_profile.consumer %}
 ...
{% else %}
 ...
{% endif %}

这实际上为您提供了基于用户类型的两个完全不同的外观/感觉选项。我还要注意 {% extends %} 可以采用字符串常量字符串变量,因此您可以使用 context_processor 来设置您所在模板的名称延伸。

I have not used django-cms so this is just off the top of my head.

There's a section of the docs called Extending the menu that looked promising. It may be unfortunate that so much of their configuration is in settings.py because it looks like you could manipulate their CMS_TEMPLATES to use different base templates (etc.) for different users. One way of getting around this (assuming that there is not a more direct route) is to add something to the UserProfile that identifies a user as consumer/producer. Then in your base.html you do:

{% if user.get_profile.consumer %}
 ...
{% else %}
 ...
{% endif %}

This effectively gives you two entirely different look/feel options based on user type. I'll also note that {% extends %} can take either a string constant or a string variable, so you could use a context_processor to set the name of template you are extending.

狠疯拽 2024-08-24 02:13:06

您需要的是 show_menu_below_id django-cms 的标签。使用各自的 id(高级字段集,位于页面表单底部)创建页面消费者和生产者,然后开始为每个页面构建页面层次结构。

然后在模板中使用标签:

<ul>
  {% if user.get_profile.consumer %}
    {% show_menu_below_id "consumer" %}
  {% else %}
    {% show_menu_below_id "provider" %}
  {% endif %}
</ul>

What you need is show_menu_below_id tag of django-cms. Create the pages consumers and producers with their respective id (advanced fieldset, on bottom of the page form) and then start building the page hierarchy for each one.

Then in the templates uses the tags:

<ul>
  {% if user.get_profile.consumer %}
    {% show_menu_below_id "consumer" %}
  {% else %}
    {% show_menu_below_id "provider" %}
  {% endif %}
</ul>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文