【问题标题】:_config.yml equivalent in DjangoDjango 中的 _config.yml 等效项
【发布时间】:2013-08-30 09:56:09
【问题描述】:

我最近开始从 Jekyll(基于 Rails 的框架)迁移到 Django,我才刚刚开始。

我试图找出 _config.yml(如果有的话)在 django 中的等价物。对于没有 Jekyll 背景的人来说,_config.yml 看起来有点像这样:

# ----------------------- #
#      Main Configs       #
# ----------------------- #
markdown: rdiscount
pygments: true
permalink: /posts/:title
rdiscount:
  extensions: [smart]

url: http://foo.bar
title: ./derp
subtitle: My code
author: Foo Bar
simple_search: http://google.com/search
description:

这样的作用是不用一遍遍地写页面标题、url等...

谢谢!

【问题讨论】:

    标签: python django web-applications jekyll code-reuse


    【解决方案1】:

    与您的配置文件最相关的等价物是 settings.py。 对于 urls 模式,您有专门的模块 - urls.py。

    页面标题之类的东西可以在任何地方定义,只要你把它拉到模板上下文中,但我认为最好的做法是使用内置站点应用程序或直接将它放在主模板中。

    【讨论】:

    • 东西在 _config.yml 中,您可以拥有 twitter 用户、g+ 帐户等值,因此每当您必须更改 twitter 帐户的名称时,只需在一个地方进行更改。这个想法是: twitter: @foo g+: plus.google.com/foobar 然后你可以用 {{ twitter }} 或 {{ g+ }} 来调用它
    • @Ricard-Sole 对于这种情况,您可以定义自己的模板上下文处理器
    猜你喜欢
    • 2012-05-07
    • 2016-07-13
    • 1970-01-01
    • 2017-08-31
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-22
    相关资源
    最近更新 更多