【问题标题】:djangocms-snippet which contains {% %} doesnot show up as placeholder content包含 {% %} 的 djangocms-snippet 不显示为占位符内容
【发布时间】:2014-12-09 02:10:34
【问题描述】:

我正在尝试使我的页脚可从前端编辑.. 使用占位符并插入页脚 sn-p。

然而,我的页脚 sn-p 包含 django 模板语言

例如

<a href="{% url terms_conditions %}">Terms and Conditions</a>

因此,如果我删除了 django 特定的东西,占位符内容不会显示出来

<a href="#">Terms and Conditions</a> 

它正在工作。

如何使它与 django 反向 url 一起工作?

我本可以给出硬编码路径,但我希望路径可翻译,所以我需要通过 url 的名称反转。

【问题讨论】:

  • urls.py 中有 terms_conditions 吗?

标签: django django-cms


【解决方案1】:

使用smartsnippets

这些有渲染django标签的能力

【讨论】:

    【解决方案2】:

    如果我没记错的话,只需创建自定义标签并将模板存储在数据库中:

    from django.template import RequestContext, Template
    @register.simple_tag
    def footer(request):
        snippet = Snippet.object.get(name='footer')
        template = Template(snippet.html)
        return template.render(RequestContext(request))
    
    {% footer request %}
    

    【讨论】:

      【解决方案3】:

      使用这个语法:

      {% url 'terms_conditions' as the_url %}
      <a href="{{ the_url }}">Terms and Conditions</a>
      

      【讨论】:

      • 这不起作用,因为 sn-p 不支持 django 模板标签。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-08
      • 2018-05-28
      • 1970-01-01
      • 2016-10-04
      • 2014-08-31
      • 1970-01-01
      相关资源
      最近更新 更多