【问题标题】:how do I Include partial html files into index.html? [closed]如何将部分 html 文件包含到 index.html 中? [关闭]
【发布时间】:2019-08-30 01:03:33
【问题描述】:

我正在使用 python 和 django 并在我的 index.html 文件中包含 html 文件,但似乎无法让它工作 - 任何帮助将不胜感激。

我将添加一些上下文.. 我已经通过 Keentheme 下载了一个主题并想在我的项目中使用它。 14:20 左右的入门教程 (https://www.youtube.com/watch?v=ApO_obOK_00) 指示我将所有 html 文件更改为 php 文件并使用 这不起作用。

html 文件包含许多指令,如下所示: '''[html-partial:include:{"file":"partials/_mobile-header-base.html"}]/'''

上面的文件位置如下: ./partials/_mobile-header-base.html

本教程仅介绍 php include 方法 - 谁能帮忙?

【问题讨论】:

  • 当你想使用 Django 的时候,为什么还要看 PHP 教程?查找 Django 教程。

标签: python html django


【解决方案1】:

您要查找的标签是{% include 'path/to/template.html' %}。您可以在 Django 的模板语言 here 中找到有关 Django 模板语言的文档以及有关 Django 模板语言 here 中其余标签和过滤器的信息。

如果您还没有,我绝对建议您阅读 Django tutorial 以全面介绍如何以 Django 方式构建数据库支持的 Web 应用程序。

【讨论】:

  • 谢谢您 - 像梦一样工作!非常有帮助。
  • @BobbyStearman 很高兴我能帮上忙!我希望你享受与 Django 相处的时光。
【解决方案2】:

Django 有一种方法可以使用 {% include %} 将 html 文件加载到模板中 确保 html 文件位于应用的模板文件夹中。

{% include 'your_app_name/your_html_file.html' %}

【讨论】:

    猜你喜欢
    • 2015-04-25
    • 1970-01-01
    • 2017-04-07
    • 2013-02-10
    • 1970-01-01
    • 2017-09-30
    • 1970-01-01
    • 2021-10-31
    • 2016-05-27
    相关资源
    最近更新 更多