Cannot access stylesheet with handlebars

拟墨画扇 提交于 2019-12-24 18:43:30

问题


I have a layout.hbs file that has a stylesheet linked to it but it doesn't seem like it is connected to the app. I already have express, path and hbs required. I might be accessing it incorrectly but my text editor is able to redirect me to the .css file path regardless. Express is using the static folder public and I tried /public and public. Both don't seem to work.

app.use(express.static(path.join(__dirname, '/public')));

My directory looks something like this

views
-layouts
public
-stylesheets
--layout

My layout hbs file looks like this

<!doctype html>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TITLE</title>
    <link rel="stylesheet" href="/public/stylesheets/style.css">
</head>
<body>
    <h1>HELLO WORLD</h1>
{{{ body }}}

</body>
</html>

回答1:


Change the below in your code

<link rel="stylesheet" href="/public/stylesheets/style.css">

to

<link rel="stylesheet" href="/stylesheets/style.css">


来源:https://stackoverflow.com/questions/47371954/cannot-access-stylesheet-with-handlebars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!