Html 加载资源失败:服务器响应状态为 404(未找到)css
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47517703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to load resource: the server responded with a status of 404 (Not Found) css
提问by Aric Peters
I'm having trouble getting my browser to display the css for the app I am creating. I have looked at the same question asked by other users but have not found any of the answers to help in my situation. When I goto the page, all that is displayed is "Hello world" with no styling even though the stylesheet is linked. When I inspect the page, I get the error:
我无法让浏览器显示我正在创建的应用程序的 css。我查看了其他用户提出的相同问题,但没有找到任何对我的情况有帮助的答案。当我转到该页面时,即使样式表已链接,显示的所有内容也是没有样式的“Hello world”。当我检查页面时,出现错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
加载资源失败:服务器响应状态为 404(未找到)
here's the structure of my application
这是我的应用程序的结构
.
./public
/css
/main.css
./routes
/index.js
./views
/index.html
./server.js
server.js:
服务器.js:
const express = require('express');
const app = express();
const port = process.env.PORT || 8080;
app.use(express.static(__dirname + '/public'));
const router = require('./routes/index.js');
app.use('/',router);
app.listen(port);
console.log('connected to port: ' + port);
index.html
索引.html
<!DOCTYPE html>
<html>
<head>
<link href="../public/css/main.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<body>
<p>Hello World!</p>
</body>
index.js
索引.js
var express = require('express');
var path = require('path');
var router = express.Router();
module.exports = router;
router.get('/', function(req,res){
res.sendFile(path.join(__dirname,'../views/index.html'));
});
采纳答案by Honsa Stunna
you have defined the public dir in app root/public
你已经在 app root/public 中定义了公共目录
app.use(express.static(__dirname + '/public'));
so you have to use:
所以你必须使用:
./css/main.css
回答by Arun J
Use the following Code:-
使用以下代码:-
../css/main.css
Note: The "../" is shorthand for "The containing directory", or "Up one directory".
注意:“../”是“包含目录”或“向上一个目录”的简写。
If you don't know the previous folder this will be very helpful..
如果您不知道上一个文件夹,这将非常有帮助。
回答by nouman shahid
i use firebase-database in html signup but last error i cannot understand if anybody know tell me . error is "Failed to load resource: the server responded with a status of 404 ()"
我在 html 注册中使用了 firebase-database 但最后一个错误我不明白是否有人知道告诉我。错误是“加载资源失败:服务器响应状态为 404 ()”