【发布时间】:2018-09-11 15:51:24
【问题描述】:
我正在使用 Nodejs、Express、MySQL、EJS。
我需要创建一个如下所示的 URL:/nameOfPage/postl
问题是:/nameOfPage/postl 不显示相应文件的 css,而 /nameofPage 确实可以正常工作。它仅呈现 HTML 并在控制台中给出此错误。 "Refused to apply style from 'http://localhost:3000/why/word.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled."
我用谷歌搜索了这个问题并给链接标签一个“type =“text/html”确实删除了错误,但 CSS 仍然不起作用。(我尝试使用和不使用类型,我将类型更改为 css 而不是html,没有任何帮助)
可能有问题的部分是错误中的 URL,“http://localhost:3000/why/word.css”,URL 的第一个参数与 CSS 文件有什么关系?我认为它正在尝试阅读它,但我不知道如何修复它。 (我有一个“单词”EJS 和 CSS 文件)
我从 MySQL 获取页面名称并循环它们并创建适当的页面。
(这是我使用的测试代码)
app.get("/why/anele", function(req,res){
let outsideL =5;
let outsideisAuthL =5;
let outsideUsernameL = 5;
outsideL = 5;
let name = 5;
let title = 5;
let description = 5;
let sidebar = 5;
let submissiontext = 5;
outsideUsernameL = 5;
let isAuthenticated = 5;
res.render("word", {name: name, description: description, sidebar:sidebar, submissiontext:submissiontext, outsideUsernameL:outsideUsernameL, outsideisAuthL:outsideisAuthL, outsideL:outsideL})})
将“/why/anele”更改为“/why”确实有效,但我需要“/why/anele”才能工作。 (/为什么/也不起作用)
“word”EJS 文件的头部。
<head>
<title>This is the Title This is the Title This is the Title</title>
<meta name="keywords" content=" vote, comment, submit ">
<meta name="description" content="internet">
<meta name="referrer" content="origin">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="word.css">
</head>
【问题讨论】:
标签: javascript html node.js express ejs