【问题标题】:Recommended way to import web components in Django templates?在 Django 模板中导入 Web 组件的推荐方法?
【发布时间】:2015-11-29 13:21:35
【问题描述】:

Google 的 Polymer 依赖于这样的 HTML 导入:

<link rel="import" href="../components/core-header-panel/core-header-panel.html">

现在我将所有自定义 Web 组件保存在静态文件夹中并像这样加载它们:

模板.html

<link rel="import" href="{% static 'polymer/my-custom-element.html' %}">

在 Web 组件中,我使用相对于文件的路径导入内容:

我的自定义元素.html

<link rel="import" href="../bower_components/polymer/polymer.html">

这是在使用 Django 时推荐的导入 Web 组件的方法还是有更好的方法?

【问题讨论】:

    标签: django django-templates polymer


    【解决方案1】:

    尽可能使用绝对路径。 我也建议你使用 django-bower。它可以以最佳方式处理凉亭静力学。

    【讨论】:

      【解决方案2】:

      使用 django-bower (https://github.com/nvbn/django-bower),在 django 模板中导入它也有点棘手,因为 'static' 会添加所有导入 url 模式,例如你的导入 url 它必须是

      <link rel="import" href="../polymer.html">
      

      【讨论】:

        猜你喜欢
        • 2016-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-15
        • 2017-04-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多