Django - 基于URL的静态内容显示

发布于 2024-08-30 07:20:05 字数 301 浏览 9 评论 0原文

我正在开发一个具有基本三栏设计的 Django 网站。左栏导航、中栏内容和右栏 URL 特定内容块。

我的问题是关于控制右列中 URL 特定内容块的最佳方法。

我正在考虑一些类似于 Flatpages 应用程序的东西,如果 URL 与预先确定的模式(可能是正则表达式?)匹配,则可以使内容可用于模板上下文。

有谁知道这样的应用程序是否已经存在?

如果没有,我正在寻找一些有关实施它的最佳方法的建议。特别是与模式与当前 URL 的匹配有关。有没有什么好的方法可以重复使用 Django URL 调度程序的部分内容来实现此用途?

I'm working on a Django site with a basic three column design. Left column navigation, center column content and right column URL specific content blocks.

My question is about the best method of controlling the URL specific content blocks in the right column.

I am thinking of something along the lines of the Flatpages app that will make the content available to the template context if the URL matches a pre-determined pattern (perhaps regex?).

Does anyone know if such an app already exists?

If not, I am looking for some advice about the best way to implement it. Particularly in relation to the matching of patterns to the current URL. Is there any good way to re-use parts of the Django URL dispatcher for this use?

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

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

发布评论

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

评论(3

旧伤还要旧人安 2024-09-06 07:20:05

Django CMS 是一个很好的建议,这取决于你想深入到什么程度。如果这只是您想要的不同类型动态内容的开始,那么您肯定应该这样做。

一个简单的一次性解决方案是这样的:

您只需要编写一个视图并在 URL 末尾添加一些变量来定义那里显示的内容。根据您需要的花哨程度,您可以创建一个简单的模型,然后将视图映射到模型键

www.example.com/content/sidecontent/jokes/

因此,如果“笑话”是您的变量 sidecontent 块(您的 Side 模型实例中的许多实例之一)的 urls.py 条目将是

(r'^content/sidecontent/(?P<side>)/$,sides.views.showsides),

,然后在您的 Side 应用程序中,您可以看到带有等的视图

def showsides(request, side):
    Sides.objects.get(pk=side)

...

Django CMS is a good suggestion, it depends on how deep you want to go. If this is just the beginning of different sorts of dynamic content you want then you should go that way for sure.

A simple one-off solution would be something like this:

You would just need to write a view and add some variables on the end of the URL that would define what showed up there. Depending on how fancy you need to get, you could just create a simple models, and just map the view to the model key

www.example.com/content/sidecontent/jokes/

so if "jokes" was your block of variable sidecontent (one of many in your sides model instances) the urls.py entry for that would be

(r'^content/sidecontent/(?P<side>)/$,sides.views.showsides),

and then in your sides app you have a view with a

def showsides(request, side):
    Sides.objects.get(pk=side)

etc...

冰雪梦之恋 2024-09-06 07:20:05

对于这样的事情,我个人会使用 Django CMS。这就像打了类固醇的平面版。

Django CMS 有页面、模板和插件的概念。每个页面都有一个关联的模板。模板具有占位符,您可以在其中插入不同的插件。插件就像迷你应用程序,可以具有基于动态模型的内容。

For something like this I personally would use Django CMS. It's like flatpages on steroids.

Django CMS has a concept of Pages, Templates, and Plugins. Each page has an associated template. Templates have placeholders where you can insert different plugins. Plugins are like mini-applications that can have dynamic model-based content.

或十年 2024-09-06 07:20:05

尽管 Django-CMS 是一个有趣的建议,但有相当多的项目专门满足您的要求 - 根据 URL 呈现内容块。我知道的主要是 django-flatblocks

Although Django-CMS is an interesting suggestion, there are quite a few projects that do specifically what you've requested - render blocks of content based on a URL. The main one that I know about is django-flatblocks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文