【问题标题】:Django path and routingDjango 路径和路由
【发布时间】:2021-12-14 03:51:32
【问题描述】:

我在应用内的文件夹结构:

pwa->static->pwa->serviceworker.js 

pwa->templates->indexPWA.html

如何在serviceworker.js 中引用indexPWA.html

var filesToCache = ["indexPWA.html"] 不起作用,因为它不是正确的路径,但正确的路径是什么?

【问题讨论】:

  • 你想在你的 JS 文件中做什么?
  • 它是一个 serviceworker,所以它应该将 indexPWA.html 写入缓存。另一种解决方案是,如果我从 views.py 中获取 indexPWA.hmtl,但我不知道如何从渲染函数中获取 static/pwa/indexPWA.hmtl 处的模板
  • "../templates/indexPWA.html"

标签: python django django-staticfiles


【解决方案1】:

您可以使用您在浏览器中定位 indexPWA.html 页面的路径。

例子:

       var filesToCache = ["/indexPWA.html"]

       var filesToCache = ["/"]

您可以通过在浏览器中打开 indexPWA.html 来检查正确的路径,并在 url 栏中检查 127.0.0.1:8000/ 之后的单词。

【讨论】:

    猜你喜欢
    • 2011-03-29
    • 1970-01-01
    • 2019-07-17
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 2018-07-06
    • 1970-01-01
    相关资源
    最近更新 更多