css - How to correctly reference .css file from handlebars while making /public/css and /public/img folders static?
问题描述
I am having trouble making my handlebars file access my .css file. My current folder structure looks like this:
root
public
css
base.css (css file)
img
ping.png (image file)
I am currently making /public/img folder and /public/css folder static using this code:
['css', 'img'].forEach(folder => app.use(express.static(__dirname + '/../public/' + folder)));
And I am referencing my .css file from handlebars using this code:
<link rel="stylesheet" href="/base.css" type="text/css" media="screen" title="no title" charset="utf-8">
I have tried to use other answers that are on stackoverflow but I don't think the answers work the same way for my project.
Is there any other mistake that I am making here? Thank you.
解决方案
我解决了我的问题。由于我制作 /public/css 文件夹和 /public/img 文件夹的 .js 文件与 /public 文件夹位于同一目录中,因此我应该使用['css', 'img'].forEach(folder => app.use(express.static(__dirname + '/public/' + folder)));
推荐阅读
- tcpdump - 如何在 tcpdump 中每个捕获的数据包之间设置分隔符?
- asp.net - SSMS 和 ASP.NET 中存储过程的不同输出
- javascript - 如何将图像文件添加到表格单元格,其中这两个元素都是使用 JS 动态创建的?
- ios - 如何同时获取键盘的大小和所选 UITextField 的 CGFrame?
- asp.net - 被 CORS 策略阻止:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段授权
- javascript - 如何按日期对数组对象进行排序?
- docker - ubuntu 18.10 和 docker 上的 ghostscript pdf/a 转换问题
- css - 如何在 CSS 中指定 == $0?
- android - Fabric apiSecret 是做什么用的?
- c - 编写嵌入式驱动程序的序列